How to fix attempt to call nil value requestmodel

here is part of a script im writing and im getting a nil value requestmodel

local function notifyPlayers(message)
TriggerClientEvent(‘chatMessage’, -1, ‘^3[Airdrop]’, {255, 255, 255}, message)
end

– Define function to spawn crate
local function spawnCrate(location)
– Generate a random model for the crate (You should replace “prop_boxpile_06a” with your desired model)
local modelHash = GetHashKey(“prop_boxpile_06a”)

-- Request the model to be loaded into the game world
RequestModel(modelHash)

-- Wait until the model is loaded
while not HasModelLoaded(modelHash) do
    Citizen.Wait(100)
end

-- Create the crate entity at a higher altitude initially
local crate = CreateObject(modelHash, location.x, location.y, 1000.0, true, true, true)

-- Set the crate's dynamic properties (e.g., allowing physics interactions)
SetEntityDynamic(crate, true)
SetEntityAsMissionEntity(crate, true, true)

-- Simulate the crate falling from the sky
for height = 1000.0, location.z, -10.0 do
    SetEntityCoordsNoOffset(crate, location.x, location.y, height, true, true, true)
    Citizen.Wait(50) -- Adjust the timing to control the speed of the falling crate
end

-- Once the crate reaches the target height, set its final position
SetEntityCoordsNoOffset(crate, location.x, location.y, location.z, true, true, true)

-- Place any additional logic here, such as attaching effects or handling interactions

-- Cleanup: Unload the model from memory to prevent resource leaks
SetModelAsNoLongerNeeded(modelHash)

-- Notify players about the deployed crate
notifyPlayers("Airdrop deployed at location: "..location.x..", "..location.y..", "..location.z)

end

Because you’re probably calling the client-sided native RequestModel in a server-side script:
image

Same thing with SetEntityDynamic and SetModelAsNoLongerNeeded.

what can i use instead sorry im new to coding

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