No such entity NETWORK_ID_FROM_ENTITY

What is the issue you’re having?

What are you trying to do?
I’m trying to make peds spawn, but they dont spawn. They do spawn if i call it, and then call it again. You can see the Warning/error im getting. I dont know how to fix this.

What have you tried already to fix the issue?
I’ve tried to setnetworkid after creating ped, but still the same issue
Error screenshot (if any):

What did you do to get this issue?

local peds = {}
local function spawnAngryPed()
    if Config.EnablePeds then
        local coords = Config.Peds
        AddRelationshipGroup(Config.PedsSettings.relationshipGroup)
        RequestModel(Config.PedsSettings.model)
        for i = 1, #Config.Peds do

            peds[i] = CreatePed(30, 1456041926, coords[i].x, coords[i].y, coords[i].z, 266.00, true, false)
                SetPedAsEnemy(peds[i], true)
                SetPedRelationshipGroupHash(peds[i], Config.PedsSettings.relationshipGroup)
                GiveWeaponToPed(peds[i], Config.PedsSettings.weapon, Config.PedsSettings.ammo, false, true)
                TaskCombatPed(peds[i], GetPlayerPed(-1))
                SetPedAccuracy(peds[i], Config.PedsSettings.accuracy)
                SetPedDropsWeaponsWhenDead(peds[i], Config.PedsSettings.dropsWeapons)
                SetPedCanRagdoll(peds[i], Config.PedsSettings.canRagdoll)
                SetEntityHealth(peds[i], Config.PedsSettings.health)
                SetPedSuffersCriticalHits(peds[i], Config.PedsSettings.suffersCriticalHits)
                SetNetworkIdExistsOnAllMachines(NetworkGetNetworkIdFromEntity(peds[i]), true)

            
        end
    end
end

Anyone know how to fix this?

After requesting a model, you need to wait for it to load. What your script basically did was request the model and immediately try to spawn peds, which of course doesnt work as the model isn’t loaded yet. When you executed it a second time there was already enough time for the first request to go through.

e.g.

RequestModel(model)
while (not HasModelLoaded(model)) do
    Citizen.Wait(0)
end
-- create ped now
2 Likes

i have this issue with my garage when i get a vehicle