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

Beautify a piece of code?

Asked by 4 years ago
Edited 4 years ago

I've this code:

local Character = plr.Character
Character.Head.Transparency= .7
Character.UpperTorso.Transparency= .7
Character.LowerTorso.Transparency= .7
Character.LeftUpperArm.Transparency= .7
Character.LeftLowerArm.Transparency= .7
Character.LeftHand.Transparency= .7
Character.RightUpperArm.Transparency= .7
Character.RightLowerArm.Transparency= .7
Character.RightHand.Transparency= .7
Character.LeftUpperLeg.Transparency= .7
Character.LeftLowerLeg.Transparency= .7
Character.LeftFoot.Transparency= .7
Character.RightUpperLeg.Transparency= .7
Character.RightLowerLeg.Transparency= .7
Character.RightFoot.Transparency= .7

Is it possible to commute this for example to:

local r15parts = {"Head", "UpperTorso", "LowerTorso", "RightUpperArm", "RightLowerArm", "LeftUpperArm", "LeftLowerArm", "RightUpperLeg", "RightLowerLeg", "LeftUpperLeg", "LeftLowerLeg", "RightHand", "LeftHand", "RightFoot", "LeftFoot"}

for _, v in pairs (r15parts) do
    Character.v.Transparency = .7
end

1 answer

Log in to vote
0
Answered by 4 years ago

You don't even need the list at all.

for i, v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
    if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("BasePart") then
        v.Transparency = 0.7
    end
end
Ad

Answer this question