I seem to be having an issue triggering a client event from with a server event.
I have thread that waits around 15 seconds from when the player loads into the server before triggering a server event. In the server event it retrieves some data from a database then sends it back to the client using a different event. The problem is it never works for the first player who joins but it does work if you reconnect or if you’re not the first player to join.
Anyone have any idea what is happening?
-- Client side event triggering
Citizen.CreateThread(function()
Citizen.Wait(15000)
TriggerServerEvent("reqData")
end)
-- Server-side handling of request
AddEventHandler("reqData", function()
if GetIdFromSource("steam", source) then
local SteamID = GetIdFromSource("steam", source)
if SteamID ~= nil then
MySQL.Async.fetchScalar("SELECT `value` FROM `database` WHERE `steamid` = @steamid", {['@steamid'] = SteamID}, function(queryResult)
if queryResult ~= "[]" or nil then
TriggerClientEvent('recData', source, queryResult)
end
end)
end
end
end)
-- Client-side data handling
AddEventHandler("recData", function(result)
-- code here doesn't get triggered at all
end)