Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to remove car after 20 seconds?

I have tried a script, and searched the web. and I found one which almost works. Only the wheels are left. It has the and wheels in a different model, within the entire carmodel. The script is inside of the Vehicle seat inside of the body.

local seat = script.Parent
local vehicle = seat.Parent

while true do
    wait(10)
    if not seat.Occupant then
        vehicle:Destroy()
    end
end

is what I have tried, can someone please explain, or fix the issue.

Thanks

8 comments

0

I didnt really get it, is the "vehicle" the entire car model? If not you need to destroy the car model.

0

So, I have a model, named F1Car. And Inside of it there are 2 more models, 1 with the wheels in it. And 1 with the other parts, and vehicle seat.

0

Try vehicle:Remove()

1

no don't try vehicle:Remove() that's deprecated and much much much worse

0

try vehicle = seat.Parent.Parent

0

tried both, neither worked

0

Your condition on line 6 seems to never pass, then.

0

Try destroying F1Car

3 answers

Put this script In the car model `` local car = script.parent

wait (20) car:Destroy``

I figured it out, I had 1 parent too little, so it didn't remove the entire model, thanks for the help :)

script.Parent.ChildRemoved:connect(function()
		wait(10) --How long it has to wait before removing
		script.Parent.Parent.Parent:remove()--It is a model inside a model inside a model, so 3 parent
	end)

1 comment

0

:remove() is deprecated, use :Destroy()

Here is a simple fix! I think you messed up on line 6. A lot of people like to do if statements when values are true and false like "if not true then" but I like to do it like "if value ~= true then"

local vehicle = script.Parent
local seat = script.Parent.Seat

while true do
	wait(10)
	if seat.Occupant == nil then
		vehicle:Destroy()
	end
end

This is a server script inside of a model.

Enjoy!

8 comments

0

For some reason, this script didnt do anything to the car.

1

um I think false and nil are the same thing as a boolean

0

hm.

0

Guarded you probably didnt set the variables, btw the king occupant is an object value, not a boolean

0

I changed all variables I could think of, and nothing happened

0

yes you can do not 7 to return false or not game to return false his script is fine

0

I would avoid if value ~= true unless you are literally looking for a true value instead of a truthy one, If you were to do if seat.Occupant ~= true it would return true on both having a driver and not having a driver since neither is equal to the literal value true

0

OP's condition was fine.

This discussion is preserved as it was. New answers, comments, and votes are closed.