Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to remove car after 20 seconds?

Asked by 5 years ago
Edited 5 years ago

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

0
I didnt really get it, is the "vehicle" the entire car model? If not you need to destroy the car model. HeyItzDanniee 252 — 5y
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. User#19623 0 — 5y
0
Try vehicle:Remove() Gameplay28 139 — 5y
1
no don't try vehicle:Remove() that's deprecated and much much much worse User#22604 1 — 5y
View all comments (4 more)
0
try `vehicle = seat.Parent.Parent` User#22604 1 — 5y
0
tried both, neither worked User#19623 0 — 5y
0
Your condition on line 6 seems to never pass, then. Goulstem 8144 — 5y
0
Try destroying F1Car HeyItzDanniee 252 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

wait (20) car:Destroy``

Ad
Log in to vote
0
Answered by 5 years ago

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)

0
:remove() is deprecated, use :Destroy() the8bitdude11 358 — 5y
Log in to vote
-2
Answered by
iladoga 129
5 years ago

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!

0
For some reason, this script didnt do anything to the car. User#19623 0 — 5y
1
um I think false and nil are the same thing as a boolean theking48989987 2147 — 5y
0
hm. iladoga 129 — 5y
0
Guarded you probably didnt set the variables, btw the king occupant is an object value, not a boolean iladoga 129 — 5y
View all comments (4 more)
0
I changed all variables I could think of, and nothing happened User#19623 0 — 5y
0
yes you can do `not 7` to return false or `not game` to return false his script is fine User#22604 1 — 5y
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 Vulkarin 581 — 5y
0
OP's condition was fine. Goulstem 8144 — 5y

Answer this question