GetPlayerFromId and TriggerServerEvent

Hello. I have a problem with server event sending info to the wrong player.

server.lua

RegisterServerEvent('ParadiseFalls:StartScavengerRun')
AddEventHandler('ParadiseFalls:StartScavengerRun', function(place)
    local xPlayer = ESX.GetPlayerFromId(source)
    local xPlayers = ESX.GetPlayers()
    for i=1, #xPlayers, 1 do
        local xPlayer2 = ESX.GetPlayerFromId(xPlayers[i])
        if xPlayer2 ~= xPlayer then
            TriggerClientEvent('ParadiseFalls:StartScavengerRun', xPlayers[i], place, false)
            print("test2")
        else
            TriggerClientEvent('ParadiseFalls:StartScavengerRun', xPlayer, place, true)
            print("test3")
        end
    end
end)

When I am the one who is triggering that server event, that should print test3, but now it always prints test2. Did I do something wrong with xPlayer definition? :thinking:

I don’t think you can compare two tables in Lua (correct me if wrong) try

if xPlayer2.source ~= xPlayer.source then
2 Likes

Correct.


@Shiroyo https://web.archive.org/web/20131225070434/http://snippets.luacode.org/snippets/Deep_Comparison_of_Two_Values_3

1 Like

Thank you. That worked :smiley: