Network ID Issues

I am having an issue with getting an entity from a network ID here is some code.

Client Side:

local enemies = {}

RegisterCommand('spawnpeds', function(source, args, rawCommand)

    local peds = {
        {
            ped = { model = 's_m_y_blackops_01' },
            coords = { x = 0.0, y = 0.0, z = 0.0, hdg = 0.0 }
        },
        {
            ped = { model = 's_m_y_blackops_02' },
            coords = { x = 5.0, y = 5.0, z = 0.0, hdg = 0.0 }
        }
    }

    for i,var in pairs(peds) do
        local hash = GetHashKey(var.ped.model)
        RequestModel(hash)
        while not (HasModelLoaded(hash)) do
            Wait(0)
        end

        local entity = CreatePed('PED_TYPE_MISSION', hash, var.coords.x, var.coords.y, var.coords.z, var.hdg, true, true)
        var.ped.netId = NetworkGetNetworkIdFromEntity(entity)
    end

    TriggerServerEvent('Server:SetData', player.serverId, peds)

end)

RegisterNetEvent('Client:SetData')
AddEventHandler('Client:SetData', function(source, data)

    for i,var in pairs(data) do
        var.ped.entity = NetworkGetEntityFromNetworkId(var.ped.netId)
        while not (DoesEntityExist(var.ped.entity)) do
             Wait(0)
        end
        print(var.ped.entity)
    end

    local enemies = data

end)

Server Side:

RegisterNetEvent('Server:SetData')
AddEventHandler('Server:SetData', function(source, data)
    TriggerClientEvent('Client:SetData', -1, data)
end)

When my friend and I get in the server and I type the command spawnpeds. When I look in the client console it gets the ped entities successful but for him, it just shows 0 and says 'GetNetworkObject: no object by id. What am I missing, I have tried an amplitude of things such as:

SetNetworkIdCanMigrate()
SetNetworkIdExistsOnAllMachines()
NetworkSetNetworkIdDynamic()
SetNetworkIdSyncToPlayer()
NetworkRequestControlOfNetworkId()
NetworkHasControlOfNetworkId()
NetworkDoesNetworkIdExist()
NetworkDoesEntityExistWithNetworkId()
PedToNet()
NetToPed()

Any help would be much appreciated!

you are passing a nil table to the server. then to the client.
you are creating a networked ped and saving its id in that table. peds table to be specific. enemies table is empty and will never get filled .
and also you do not need to pass player server id as source and you do not need to write it in handler argument in server side.
Client:
TriggerServerEvent('hiitsme')
Server :

RegisterNetEvent('hiitsme')
AddEventHandler('hiitsme',function()
src = source
print(GetPlayerName(src))
end)

you need to pass the peds table instead of enemies at the Server:SetData event then in the Client:SetData enemies will be filled with it.

1 Like

and also
ped types are not string.
here is a list of possible ped types that you can set when creating a ped

Michael = 0  
Franklin = 1  
Trevor = 2  
Army = 29  
Animal = 28  
SWAT = 27  
LSFD = 21  
Paramedic = 20  
Cop = 6  
Male = 4  
Female = 5   
Human = 26  
1 Like

I realized that and I seem to still be having the issue.

Sorry, this was example code I wrote up. I accidently put enemies instead of peds, but the same thing still happens.

Checkout this topic, maybe you can get your answer there.

[HELP] NetworkGetNetworkIdFromEntity

2 Likes