Hi, I am trying to create a script where if no one is in the car for at least 30 seconds the car gets removed. I have tried creating different scripts but they never end up working and I need a bit of help, here is one script:
function onTouch(seat)
local player = seat.Parent:FindFirstChild("Humanoid")
if (player ~= nil) then
print("No del")
elseif (player == nil) then
print("del")
wait(30)
script.Parent.Parent.Parent:Destroy()
end
end
script.Parent.Touched:connect(onTouch)
So I made this one that if there is no humanoid touching the seat it gets removed but it does not work and I am confused and do not know why.
I lost the other one I made but it had something to do with this
if script.Parent.Occupant == nil then
wait(30)
script.Parent.Parent.Parent:Destroy()
elseif script.Parent.Occupant ~= nil then
print("Human in car")
end
This last one was big and confusing but it worked, it put the value into the local player and when you'd click it the value would change to true or false. But afterwards I tried adding in another script to destroy the car if the value was false. The script below was in the gui
people = false
script.Parent.MouseButton1Click:connect(function()
print("does")
if game.Players.LocalPlayer:FindFirstChild("Value") == nil then
Instance.new("BoolValue").Parent = game.Players.LocalPlayer
game.Players.LocalPlayer.Value.Value = true
else
if people == false then
game.Players.LocalPlayer.Value.Value = false
people = true
elseif people == true then
game.Players.LocalPlayer.Value.Value = true
people = false
if game.Players.LocalPlayer.Value.Value == true then
print("parked")
end
end
end
end)
this script here was in the vehicle seat. Separate script in vehicle seat.
if game.Players.LocalPlayer.Value.Value == false then
wait(30)
script.Parent.Parent.Parent.Destroy()
elseif game.Players.LocalPlayer.Value.Value == true then
print("In car")
None of these scripts worked and I do not know why, I need help with understanding this please. I tried changing some "elseif" to just "else" Thank you very much for your time. Probably an easy mistake, after all it is 12:44AM here

3 comments
That will destroy the car after 30 seconds, even if a player is still in it (which just adds more time when they first get in). The player would have to keep hopping in and out to keep the car.
Would this edited version work?
Yeah I think so