GetPlayerFromServerId always returns -1

Hello, I have a problem with my script: I can’t get player from server id:

server-side.lua:

for _, playerid in ipairs(GetPlayers()) do -- getting all players
            if(Player(playerid).state.team == 2) then 
                  print(playerid) -- output: 1
                  TriggerClientEvent('setAlienDark',-1, playerid)
            end
      end

client-side.lua:

RegisterNetEvent('setAlienDark')
AddEventHandler('setAlienDark', function(src)
    print(src) -- output:1

    local playerId = GetPlayerFromServerId(src)
    print(playerId) -- output: -1
end)

I’ve tried running this with multiple players with different server ids, but they all get -1 from GetPlayerFromServerId. Any ideas why? Thanks :slight_smile:

Player probably isn’t in your ‘bubble’? If they are further away than 300 units, they get unloaded and your client can’t reference them.
See OneSync 'Infinity': how to use it for more info

1 Like