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!

1 comment
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?