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!
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
All you gotta do is put "break" after you delete the parent.