I created a car and I want it to spawn if it is not currently on the spawn point (so if a player drives it away, another player can come and get another car.)
but for some reason, after it spawns the car once, the whole script stops.
local spawner = script.Parent.PrimaryPart
local car = game.ReplicatedStorage.MailTruck
local carPresent = false
for i,v in pairs(spawner.Parent:GetChildren()) do
if v:IsA("Part") or v:IsA("UnionOperation") then
v.Transparency = 1
v.CanCollide = false
end
end
local function isCar(car)
for i,v in pairs(spawner:GetTouchingParts()) do
if v.Name == car.Name then
carPresent = false
else
carPresent = true
end
end
end
while wait() do
for i = 0, 10, 1 do
wait(1)
isCar(car)
print(carPresent)
if carPresent == true then
return
elseif carPresent == false and i > 9 then
local clone = car:Clone()
clone.Parent = workspace
clone.PrimaryPart.CFrame = spawner.CFrame
carPresent = true
return
end
end
end