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

Odd error, can someone explain it to me?

Asked by
Necrorave 560 Moderation Voter
10 years ago

I have a simple script here that deletes a model if "endGame" is in the Workspace. If it is not, then it waits 8 seconds before destroying it.

It runs through as it should perfectly, however I seem to be getting an error nonetheless.

My error:

23:35:19.585 - Workspace.Dog.Remove:4: attempt to index field 'Parent' (a nil value)

My script:

x = 0
while true do
    if game.Workspace:FindFirstChild("endGame") or x == 8 then
        script.Parent:Destroy()
    else
        wait(1)
        x = x + 1
    end
end

I would just like someone to explain to me why I am getting this error, and why it is still going through the script as though there was none.

Thanks!

4 answers

Log in to vote
1
Answered by 10 years ago

ignore it, it just ran the loop 1 more time after it was deleted because scripts are very fast, but since it already deleted itself, it couldnt check itself for endgame again

Ad
Log in to vote
0
Answered by
Vividex 162
10 years ago

Since you have it in a loop while true do it will try to keep deleting the Model, but after the first time its ran its gone so its nil meaning it doesn't exist so it errors.

Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
10 years ago

Try Not using >while true do

Here is the script without while true do in it.

x = 0
    if game.Workspace:FindFirstChild("endGame") or x == 8 then
        script.Parent:Destroy()
    else
        wait(1)
        x = x + 1
    end
0
I need it to through this process many times until the parent is deleted. This would not do what I wish it to do. Also, if 'x' never goes past 1, what is its purpose? Necrorave 560 — 10y
Log in to vote
0
Answered by
spynaz 30
10 years ago

All you gotta do is put "break" after you delete the parent.

0
Why? If I deleted the parent this script belonged to, then it will not proceed with the rest of the script anyways. If the parent is deleted, so are its children. Necrorave 560 — 10y
0
ok then why does it still error for him??? spynaz 30 — 10y
0
you* spynaz 30 — 10y

Answer this question