[SLOVED] TriggerClientEvent Not working need a second pair of eyes

Folder structure:
Life> mainc.lua, mains.lua, __resource.lua

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.

Code:
Server-side code: Filename: mains.lua

AddEventHandler("life:getPlayerData",function()
    print("Getting Data.........")
    TriggerClientEvent('life:Spawn', source)
end)

Client-side code: Filename: mainc.lua

RegisterNetEvent('life:Spawn')
AddEventHandler('life:Spawn', function()
    msg("Spawn works")
    TriggerServerEvent('life:test', -2)
end)

Are you calling the event “life:getPlayerData” from the server or the client?

also I followed your stream if I have time I might stop in a say a few words idk.

1 Like

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

1 Like

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)

have you tried printing out “source” on the server to see if it is the correct source integer?

1 Like

Ohhhhh no I haven’t thank you I’ll try that!

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.

1 Like

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.

Just pass the source manually.

Just update your event to receive an argument

AddEventHandler('life:getPlayerData', function(source)

then when triggering the event from the

"life:checkPlayerData"

do

TriggerEvent('life:getPlayerData', source)
1 Like

Thank you I am trying that now on stream