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

Script is saying that I should use an indentation?

Asked by 5 years ago

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.

0
indent. Elixcore 1337 — 5y
0
Remove the end on line 1 and only use one end on line 3. elseif can't be used outside an if statement TerrodactyI 173 — 5y

1 answer

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

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.

Ad

Answer this question