seat = script.Parent s = script function onChildAdded(child) if child.Name == "SeatWeld" then local human = child.part1.Parent:findFirstChild("Humanoid") if (human ~= nil) then print("ln") end end end function onChildRemoved(child) if (child.Name == "SeatWeld") then local human = child.part1.Parent:findFirstChild("Humanoid") if (human ~= nil) then print("Out") wait(20) script.Parent.Parent:Destroy() end end end script.Parent.ChildAdded:connect(onChildAdded) script.Parent.ChildRemoved:connect(onChildRemoved)
Ok, thanks for reading and hopefully answering! So anyways, when a player gets into a car and gets out, the car will delete it self with his code:
if (human ~= nil) then print("Human OUT") script.Parent.Parent:Destroy() -- this one end
but im trying to use a ultimate driving type car spawner, but of course people sometimes dont go into the cars So how would i make a car delete itself within 20 seconds if nobody goes into it? Thanks!
I found this code here, I think it can help you
local Timeout = 20 --How long the vehicle can be empty before it despawns local function timedOut() for i=1, Timeout do wait(1) if vehicleSeat.Occupant then return end end return true end vehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function() if vehicleSeat.Occupant == nil and timedOut() then vehicle:Destroy() end end)
Make sure to change vehicleSeat to the seat of the car so the code works.
You may try this:
local seat = script.Parent wait(20) if not script.Parent.ChildAdded then script.Parent.Parent:Destroy() end if script.Parent.ChildAdded then return end