Objects spawning above coords

So I have this code here in a config file

pickupLocations = { -- All the objects to be spawned inside of the warehouse
        [1] = vector3(1003.62, -3091.69, -39.0),
        [2] = vector3(1010.83, -3097.02, -39.0),
        [3] = vector3(1003.7, -3097.15, -39.0),
        [4] = vector3(1006.13, -3091.76, -39.0),
        [5] = vector3(1008.44, -3091.57, -39.0)
    }

and then this code in a client file

    for _, spawnLoc in pairs(WarehouseData.pickupLocations) do
        local randObj = WarehouseData.listOfObjects[math.random(1, #WarehouseData.listOfObjects)]

        RequestModel(randObj)
        while not HasModelLoaded(randObj) do -- Not sure if I actually need this
            Citizen.Wait(1000)
        end

        local pickupObj = CreateObject(randObj, spawnLoc.x, spawnLoc.y, spawnLoc.z)
        FreezeEntityPosition(pickupObj, true)
        PlaceObjectOnGroundProperly(pickupObj)

        table.insert(objects, pickupObj)
end

and for some reason when the script first loads when the server loads, the objects will be above the ground in the air sort of and if you were to re run the code (restarting script or anything that triggers that bit of code) they then get placed properly on the ground. How would I go about making it so that they dont keep spawning in the sky when the server first loads?

Only spawn them when the player gets close enough.
PlaceObjectOnGroundProperly doesn’t work when too far away.

So right now they spawn when the player enters the building and then de spawn when the player leaves. So if the server starts up and the player enters the building for the first time, all objects are floating but if they leave and re enter, they all sit on the ground like they are suppose to

You can also try using CreateObjectNoOffset instead and make sure collisions have loaded before trying to spawn everything.

Hi :wave:

Not sure if you know this, but when taking a vector eg. (/vector3), fivem takes the vector but at a 0.8 higher value then the floor you are standing on.

Try lowering your vector by 0.8 or 1, this might help placing them on the ground where the should be providing that you just used /vector3.

Height is the 3rd value in the vector 3.

when you copy coords, fivem It doesn’t take the coordinates of your feet
but your body
so you need lover z coord on 1.0