I have a trouble with my Custom resource, i need spawn a car on the other side of the map, but 50-50% to succeed. I don’t know why, I have read many descriptions on the subject.
The Important part of the code:
var vh = "adder";
RequestModel( vh );
spawnCar(vh, x, y, z, a, true, false);
let tryes = 0;
function spawnCar(car, x,y,z, a, b1, b2){
tryes ++;
if(HasModelLoaded(car)){
auto = CreateVehicle(car, x,y,(z+0.15), a, b1, b2)
// success
} else {
if(tryes > 5){
//fail
} else {
setTimeout(function(){
spawnCar(car, x,y,z, a, b1, b2);
}, 200);
}
}
}
i need to spawn a car on the other side of the map
You might be facing issues because the “other side of the map” might not be loaded for the player. This causes the vehicle to spawn then endlessly fall through the map because it doesn’t have anything to collide with.
Otherwise, perhaps try to spawn the vehicle only when the player is within range of that “side of the map”, perhaps a 250.0 or 500.0 radius would do the trick.