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.
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
.