Why my vehicle still despawn… after i script this code
local myPed = GetPlayerPed(-1)
local player = PlayerId()
local vehicle = GetHashKey('police2')
RequestModel(vehicle)
while not HasModelLoaded(vehicle) do
Wait(1)
end
local spawned_car = CreateVehicle(vehicle, 412.857696533203, -981.011474609375, 29.4276905059814, 181.814880371094, true, false)
SetVehicleOnGroundProperly(spawned_car)
SetModelAsNoLongerNeeded(vehicle)
SetVehicleHasBeenOwnedByPlayer(spawned_car, true)
local id = NetworkGetNetworkIdFromEntity(spawned_car)
SetNetworkIdCanMigrate(id, true)
Citizen.InvokeNative(0x629BFA74418D6239,Citizen.PointerValueIntInitialized(spawned_car))
the vehicle seem to despawn as the same… SetVehicleHasBeenOwnedByPlayer doen’t work?
It’s real name is ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED
You tag this car as not needed, so the game remove it as soon as it can
Remove this line and it will stop despawning. But be careful, it won’t despawn even when exploded.
I have no idea what SetNetworkIdCanMigrate does. I don’t use it and as long as I tested, I can see the cars I spawn and my friend too without it.
I can only recommend you to try with and without, I don’t find a lot of informations on this function.