Beginner scripter who has made a car despawning script. The script properly ads up the 'Seconds' Int value until reaching 20. When it reaches 20 it deletes the car as it should, however when getting into the car the Int Value doesn't go to 0 but instead continues climbing. I suspect this is something to do with my Loop of If statement.

And help appreciated, thanks in advance.

Secs = script:FindFirstChild("Seconds")
Occupant = script.Parent.Occupant
car = script.Parent.Parent


while true do
            wait(1)

            if Occupant == nil then
                Secs.Value = Secs.Value + 1
                    if Secs.Value == 20 then
                        car:Destroy()
                        end

            elseif Occupant ~= nil then
                Secs.Value = Secs.Value - Secs.Value 
                print("hello")

end
            end

-should also add that "hello" isn't being printed either

5 comments

0

Hi sir, try putting line 2 after the wait(1)

0

Thanks heaps mate. Mind sharing why it works now?

0

You need up update the Occupant state, you didn’t do this, which permanently set the Occupant variable to nil, since the Occupant Humanoid didn’t exist at the time you called it.

0

This is a mistake I’ve been seeing lately with beginners, not sure why this has arisen. I believe you’re trying to store a reference to the Occupant property, this of which you cannot do. By saying .Occupant, you store the Value of Occupant not it’s property (You’re essentially calling a read)

0

Okay, thanks for your helps guys.