RequestModel fatal error

Hello. I have a code which spanws hostile peds on the map, but sometimes this fatal error appears. I tested it for every ped and it seems that they are all working fine, so the models are not the problem.

Error:

Native 936d27a58df860ac is RequestModel native.

Part with error client.lua

Spawn = Spawners.StabCity[math.random(#Spawners.StabCity)]
Skin = MonsterSkins.Zombies[math.random(1, #MonsterSkins.Zombies)]
print("DEBUG: Skin name: " .. Skin)
RequestModel(GetHashKey(Skin))
while not HasModelLoaded(GetHashKey(Skin)) do
       RequestModel(GetHashKey(Skin))
       Citizen.Wait(500)
end
local Ped = CreatePed(4, GetHashKey(Skin), Spawn.x, Spawn.y, Spawn.z, 0.0, true, true)

Whole thread in client.lua

Citizen.CreateThread(function()
    while true do
        if SpawnMonsters ~= nil then
            if SpawnMonsters == "Tier1" then
                if CurrentPlace == "Stab City" and #EntityTables.Zombies < 21 then
                    print("DEBUG: Table size: " .. #EntityTables.Zombies)
                    print("DEBUG: Spawning zombie")
                    Spawn = Spawners.StabCity[math.random(#Spawners.StabCity)]
                    Skin = MonsterSkins.Zombies[math.random(1, #MonsterSkins.Zombies)]
                    print("DEBUG: Skin name: " .. Skin)
                    RequestModel(GetHashKey(Skin))
                    while not HasModelLoaded(GetHashKey(Skin)) do
                        RequestModel(GetHashKey(Skin))
                        Citizen.Wait(500)
                    end
                    local Ped = CreatePed(4, GetHashKey(Skin), Spawn.x, Spawn.y, Spawn.z, 0.0, true, true)
                    if Skin == "Zombie4" then
                        SetPedSuffersCriticalHits(Ped, false)
                        SetPedMaxHealth(Ped, 600)
                        SetEntityHealth(Ped, 600)
                    end
                    SetPedAccuracy(Ped, 25)
                    SetPedSeeingRange(Ped, 300.0)
                    SetPedHearingRange(Ped, 300.0)
                    SetPedFleeAttributes(Ped, 0, 0)
                    SetPedCombatAttributes(Ped, 16, 1)
                    SetPedCombatAttributes(Ped, 17, 0)
                    SetPedCombatAttributes(Ped, 46, 1)
                    SetPedCombatAttributes(Ped, 1424, 0)
                    SetPedCombatAttributes(Ped, 5, 1)
                    SetPedCombatRange(Ped,2)
                    SetPedAlertness(Ped,3)
                    SetAmbientVoiceName(Ped, "ALIENS")
                    SetPedEnableWeaponBlocking(Ped, true)
                    SetPedRelationshipGroupHash(Ped, GetHashKey("Monsters"))
                    DisablePedPainAudio(Ped, true)
                    SetPedDiesInWater(Ped, false)
                    SetPedDiesWhenInjured(Ped, false)
                    SetPedDiesInstantlyInWater(Ped,true)
                    SetPedConfigFlag(Ped,100,1)
                    ApplyPedDamagePack(Ped,"BigHitByVehicle", 0.0, 9.0)
                    ApplyPedDamagePack(Ped,"SCR_Dumpster", 0.0, 9.0)
                    ApplyPedDamagePack(Ped,"SCR_Torture", 0.0, 9.0)
                    StopPedSpeaking(Ped,true)
                    if not NetworkGetEntityIsNetworked(Ped) then
                        NetworkRegisterEntityAsNetworked(Ped)
                    end
                    table.insert(EntityTables.Zombies, Ped)
                end
                for i, ped in pairs(EntityTables.Zombies) do
                    if DoesEntityExist(ped) == false then
                        table.remove(EntityTables.Zombies, i)
                        DeleteEntity(ped)
                    end
                    if IsPedDeadOrDying(ped, 1) == 1 then
                        SetEntityAsNoLongerNeeded(ped)
                        table.remove(EntityTables.Zombies, i)
                        print("DEBUG: Removing ped id: " .. i)
                        --Quantity = Quantity - 1
                    else
                        SetAmbientVoiceName(ped, "ALIENS")
                        DisablePedPainAudio(ped, true)
                        SetPedDiesInWater(ped, false)
                        SetPedDiesWhenInjured(ped, false)
                    end
                end
            end
            Citizen.Wait(4000)
        else
            Citizen.Wait(10000)
        end
    end
end)

Double check that all your ped entries are valid, also it might be worth deliberately passing something incorrect to the native, and seeing if it behaves in the same way.

I double checked every model and they are all working fine. I tried putting invalid skin name and the script doesn’t spawn the zombie as expected, but it also doesn’t throw ANY error :thinking: I also tried using vanilla skins and same thing happens after some time.

If anyone is curious, I fixed that by just requesting models on first player spawn. No more errors, no more problems.