Possible bug with latest server versions, tested with 3382, 3394

Hello, I think there is a possibly a new bug with the latest server builds. On 3348, the following code works properly:

server.lua:

Citizen.CreateThread(function()
  Wait(2000)

  while true do
    Wait(1)
    -- do stuff
  end
end)

AddEventHandler("onResourceStart", function(resource)
  if (resource == GetCurrentResourceName()) then
    print("Time:", GetGameTimer())
    
    Wait(1000)

    print("Time:", GetGameTimer())
    TriggerClientEvent("testEvent", -1)
  end
end)

client.lua:

RegisterNetEvent("testEvent")
AddEventHandler("testEvent", function()
  print("Event triggered.")
end)

fxmanifest.lua:

-- Resource Metadata
fx_version "cerulean"
games {"gta5"}

client_scripts {
    "client.lua"
}
server_script "server.lua"

However, on 3382 and 3394, it appears to skip the Wait(1000) in the onResourceStart event like it’s not there. Here’s the server output:

cfx> restart test
Stopping resource test
Creating script environments for test
Time:   1229469
Started resource test
Time:   1229474

and the client event never gets triggered.

However, if I change the server file to

Citizen.CreateThread(function()
  Wait(2000)

  while true do
    Wait(1)
    -- do stuff
  end
end)

AddEventHandler("onResourceStart", function(resource)
  if (resource == GetCurrentResourceName()) then
    Citizen.CreateThread(function()
      print("Time:", GetGameTimer())
      
      Wait(1000)

      print("Time:", GetGameTimer())
      TriggerClientEvent("testEvent", -1)
    end)
  end
end)

, the event triggers properly and the server output is as follows:

cfx> restart test
Stopping resource test
Creating script environments for test
Started resource test
Time:   1381215
Time:      1382232

Is this an intended change? Thanks.

Hm, this should’ve been fixed a while ago with the CreateThreadNow fix. :confused:

1 Like

This is still an issue with 3428. The above should be a repro for it. If not, I can try to figure out what else could be causing it.
Edit: Picture just in case
image

I believe this should fix it: fix(scripting/lua): also set curTime in CreateThread by Frosty-Ice ¡ Pull Request #618 ¡ citizenfx/fivem ¡ GitHub

It wouldn’t.

A fix would rather be unconditionally reading time on a CreateThreadNow anyway, instead of relying on the last thread update.

So hopefully like this

Verified fixed in 3455. Thanks