Hello. I’m having trouble with my car spawner.
So after I’ve spawned the car there is a timer and if the car doesn’t move away from the spawn location within that time I want the car to be despawned (destroyed) but my current script doesn’t seem to work.
ServerScript:
local rep = game.ReplicatedStorage
local events = rep.Vehicles.RemoteEvents
local cars = rep.Vehicles.Cars
local planes = rep.Vehicles.Planes
local armor = rep.Vehicles.Armor
local locations = {
game.Workspace.CarSpawner.Locations.Location1,
game.Workspace.CarSpawner.Locations.Location2,
game.Workspace.CarSpawner.Locations.Location3
}
events.Jeep.OnServerEvent:Connect(function(plr)
if locations[1].Occupied.Value == false then
local jeep = cars.Jeep:Clone()
jeep.Name = plr.Name.."'s Jeep"
jeep.Parent = workspace
jeep:MoveTo(locations[1].Position)
local spawnPosition = jeep.Vehicle.Model.DriveSeat.Position
plr.PlayerGui.Interface.VehicleSpawnerFrame.Visible = false
locations[1].Occupied.Value = true
wait(5)
if jeep.Vehicle.Model.DriveSeat.Position == spawnPosition then
jeep:Destroy()
end
locations[1].Occupied.Value = false
end
end)```
If you know how to fix this please help!
It most likely spawn in to that Position then settled a bit. That would make it so it’s not perfectly in that Position when checked. A check like that would have to be .000, .000, .000 accurate.
Ran into somthing like this and went to timer. If not taken within the limmit it is removed.
Doing some checking..
I put a transparent/no colliding box part out, made a region from that,
then checked inside the region for a Vehicle Seat..
local part = workspace:WaitForChild("Part")
local region = Region3.new(part.Position - part.Size / 2, part.Position + part.Size / 2)
local partsInRegion = workspace:FindPartsInRegion3(region, nil, math.huge)
for _, part in ipairs(partsInRegion) do
if part:IsA("VehicleSeat") then
print("detected")
break
end
end
Once you have the numbers needed you wouldn’t need the box or keep it, works both ways.