Problem:
I can call TriggerServerEvent’s no problem but if I want to call a Client-side TriggerClientEvent it won’t run the function. Server prints Getting Data. The client-side code works if I call it from the client side. I have tried dofile() and requires() after the TriggerClientEvent didn’t work.
Thank you so much for your reply,
I am calling life:getPlayerData and to test to see if it was calling I added the print(“Getting data…”) and it prints in the server console.
but where are you calling it from. Are you calling TriggerServerEvent(“life:getPlayerData”) from the client or are you calling TriggerEvent(“life:getPlayerData”) from the server
Ok so I first do a
Client-side RegisterCommand("debug", function (source) TriggerServerEvent('life:checkPlayerData') TriggerEvent("chatMessage", "[Main Debuger]", {255,0,0}, "debug......") end, false)
and that goes to a server-side where I
RegisterNetEvent("life:checkPlayerData")
AddEventHandler("life:checkPlayerData",function ()
playerId = GetPlayerIdentifier(source)
playerName = GetPlayerName(source)
findPlayer = MySQL.Sync.fetchScalar("SELECT COUNT(1) FROM players WHERE `id` = @identifier", {['@identifier'] = playerId})
print(findPlayer)
if (findPlayer <= 0) then
TriggerEvent('life:makePlayerData')
print("No Data")
else
TriggerEvent('life:getPlayerData')
print("Have Data")
end
end)
actually wait… It actually doesn’t work the way you have it. “source” only exists when the event is triggered by the client. TriggerEvent does not pass the source argument. You will need to pass that as an argument manually.
'life:getPlayerData'
is triggered by another server event so source would only exist inside of
"life:checkPlayerData"
so you will need to pass source from the checkPlayerData event o the getPlayerData event.
Ok So could I use a global var to hold it and then holder = source and the in the life:getPlayerData pass holder to the client-side or do I have to keep it as the source?
That wouldn’t be a good way to do that. Server variables are global to ANY client events incoming meaning if 2 clients say triggered it at the same time it would overlap.