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

Script keeps printing error?

Asked by 9 years ago

So whenever I run this script, an error is printed: 17:01:00.973 - Workspace.Player1.pet.movePetGhostdeeri:73: attempt to index local 'wallzz' (a nil value)

This is the script:

function checkpowerup()
while wait() do
    if powerup.Value == true then
    for i = 0.4, 1.3, 0.1 do
        local wallzz = script.Parent.Parent.Torso:WaitForChild("sheeld"):FindFirstChild("Shield")
        wallzz.Mesh.Scale = Vector3.new(1, 1, 1)
        wallzz.Transparency = i
    end
    end
end
end

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

This means, unsurprisingly, that wallzz is nil.

You are assigning it on line 5, so that probably means you are assigning it to nil.

That is, there is no child called "Shield" inside the child named "sheeld" -- that's the case when :FindFirstChild returns nil.


First, check the spellings and capitalizations.

If there is seemingly a child, it's possible that somehow the :WaitForChild finishes only moments before "Shield" appears.

If that's the case, just use another :WaitForChild to find "Shield":

local wallzz = script.Parent.Parent.Torso:WaitForChild("sheeld"):WaitFortChild("Shield")

If you aren't convinced that "Shield" will necessarily be there, then you should check that wallz exists before doing anything to it:


local wallzz = script.Parent.Parent.Torso:WaitForChild("sheeld"):FindFirstChild("Shield") if wallzz then wallzz.Mesh.Scale = Vector3.new(1, 1, 1) wallzz.Transparency = i end
Ad

Answer this question