Hello, I am trying to make a system where if you spawn a car, you have 10 seconds to get in before it despawns. This is for a game called Track8 but it seems that the spawner breaks the despawner. Note: MouseButton1Click and wait(1) are placeholders Car spawner:
script.Parent.MouseButton1Click:connect(function(GetCar)
local Mod = game.ServerStorage.RallyRenault --Change test to whatever you have named the item you want to spawn
local clone = Mod:Clone()
clone.DeSpawn.Disabled = false
clone.Name = "RallyRenaultClone"
clone.Parent = workspace
clone:MakeJoints()
end)
Despawner:
local car = script.Parent
local seat = script.Parent.DriveSeat
-- change the car and seat variables if they are different in your case.
seat:GetPropertyChangedSignal("Occupant"):Connect(function(newOccupant)--Sets up the connection to when the Occupant changes it's value.
if newOccupant == nil then--Checks if the new value is nil
wait(1)
if seat.Occupant == nil then--Checks if it is still nil
car:Destroy()
end
end
end)

2 comments
change workspace to game.workspace and for the despawner do a wait
Where? Also the despawner also has a wait.