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

Odd error, can someone explain it to me?

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

✓ Accepted answer

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

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.

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

1 comment

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?

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

3 comments

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.

0

ok then why does it still error for him???

0

you*

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