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

Script is saying that I should use an indentation?

In my game, there is a script but it gives me a W008 error

if prt.Name:find("Leg") then prt.Transparency = 1 end
elseif prt:findFirstChild("NameTag") then prt.Head.Transparency = .5 prt.Head.Reflectance = 0 prt.Head.BrickColor = BrickColor.new("Institutional white")
end end

prt:findFirstChild("NameTag") is the part where it gives the error. I'm hoping that someone could help me.

2 comments

0

indent.

0

Remove the end on line 1 and only use one end on line 3. elseif can't be used outside an if statement

1 answer

✓ Accepted answer

You should generally keep your code to doing one thing per line. If you don't, it's easy to miss (important!) details when you're re-reading later, after you've forgotten exactly how it works.

Your second line is doing 4 things!

Properly formatted, your code should look like this:

        if prt.Name:find("Leg") then
           prt.Transparency = 1
        end
    elseif prt:FindFirstChild("NameTag") then
        prt.Head.Transparency = .5
        prt.Head.Reflectance = 0
        prt.Head.BrickColor = BrickColor.new("Institutional white")
    end
end

Every new "block" (between a then and a else/end; between a do and end; between a repeat and until; etc) should be one level to the right.

Also note that :findFirstChild is deprecated in favor the of the more consistently cased :FindFirstChild.

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