Get Entity ID from a Network ID

I’m creating a PED server side, and i’m trying to get his client’s entity ID so i can edit the ped. But nothing work.

SERVER SIDE:

local serverped = CreatePed(4, 0x705E61F2, x, y, z, 0, false, true)
local netserver = NetworkGetNetworkIdFromEntity(serverped)

CLIENT SIDE:

local PedToNet = NetworkGetEntityFromNetworkId(netserver)
SetEntityHealth(PedToNet, 0)
SetEntityInvincible(PedToNet, true)
SetBlockingOfNonTemporaryEvents(PedToNet, true)
FreezeEntityPosition(PedToNet, true)
print('Network '..netserver)
print('Entity '..PedToNet)

The only things that work is the netserver, who export the right netid. But the PedToNet export 0. Can someone help me?? Thx in advance

On server side you need to wait a little after creating the entity before you can get its net id.

E.g.:

local serverped = CreatePed(4, 0x705E61F2, x, y, z, 0, false, true)
while (not DoesEntityExist(serverped)) do
    Wait(0)
end
local netserver = NetworkGetNetworkIdFromEntity(serverped)

Also your client needs to be in range of the ped. Adding another Wait will help as well.

while (not NetworkDoesEntityExistWithNetworkId(netserver)) do
    Wait(0)
end
-- continue with your code

Though you should probably add timeouts as well.

1 Like

you the goat!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.