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

this is a easy script but how do i fix this attempt to index field 'Parent' (a nil value)?

Asked by 5 years ago
while true do
    wait()
if script.Parent.Value <0  then
    script.Parent.Value = 0
    wait(.31)
    script.Parent.Parent:Destroy()
    end
end 
-- lol
0
On line three maybe it needs to be ' if script.Parent.Value <<0 then ' barrettr500 53 — 5y
0
it did not work, its line 6 that give the error helleric -3 — 5y
0
Where is this script? lunatic5 409 — 5y

1 answer

Log in to vote
1
Answered by
Fifkee 2017 Community Moderator Moderation Voter
5 years ago
Edited 5 years ago

Well, if you destroyed the script's parent on the first iteration, the parent will not be existent anymore. Nil is the same thing as nothing, null, nonexistant, void.

If it manages to go through the if condition twice, it will try to destroy something that is not there. So, it will attempt to destroy nothing.

And, since Lua hates when something goes wrong (unlike html), it will error and cry under the sheets. So, you want to prevent that, right?

To prevent it, just check if the script has a parent, and if the script's parent's parent is available.

TL;DR, you should check if the scripts parent (and the script's parent parent) isn't nil.

P.S. To save yourself another line, instead of doing

while true do
    wait()
    print'green eggs in ham still hates sam i am'
end;

you can do:

while wait() do
    print'green eggs in ham still hates sam i am'
end;
0
Don't encourage bad practices. while wait() do is bad practice User#19524 175 — 5y
0
how is it bad practice? Fifkee 2017 — 5y
Ad

Answer this question