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

How do you script body color changes on an r15 avatar?

Asked by
Hizzaa -3
5 years ago

I have this customization GUI created and I scripted it kinda like this

StarterGUI>MainMenu>CustomizationFrame>Frame>TextButton(PastelBlueSkinColor)> Value(Pastel Blue)

and tried 2 different scripts

Player = game.Players.LocalPlayer
Character = Player.Character
x = script.Parent.Value.Value
script.Parent.MouseButton1Click:Connect(function ()
    Character.Head.BrickColor = x
    Character("HeadColor3").BrickColor = x
    Character("RightArmColor").BrickColor = x
    Character("RightArmColor3").BrickColor = x
    Character("RightLegColor").BrickColor = x
    Character("RightLegColor3").BrickColor = x
    Character("TorsoColor").BrickColor = x
    Character("TorsoColor3").BrickColor = x
    Character("LeftArmColor").BrickColor = x
    Character("LeftArmColor3").BrickColor = x
    Character("LeftLegColor").BrickColor = x
    Character("LeftLegColor3").BrickColor = x

end)

and i also tried

Player = game.Players.LocalPlayer
Character = Player.Character
x = script.Parent.Value.Value
script.Parent.MouseButton1Click:Connect(function ()
    Character.Head.BrickColor = x
    Character("RightUpperArm").BrickColor = x
    Character("RightLowerArm").BrickColor = x
    Character("RightHand").BrickColor = x
    Character("RightUpperLeg").BrickColor = x
    Character("RightLowerLeg").BrickColor = x
    Character("RightFoot").BrickColor = x
    Character("LowerTorso").BrickColor = x
    Character("UpperTorso").BrickColor = x
    Character("LeftUpperArm").BrickColor = x
    Character("LeftLowerArm").BrickColor = x
    Character("LeftHand").BrickColor = x
    Character("LeftUpperLeg").BrickColor = x
    Character("LeftLowerLeg").BrickColor = x
    Character("LeftFoot").BrickColor = x


end)

But neither work and ive been stuck on this for a day or 2 so idk help pls

0
To index, you use [], or the . notation. not (). () is for function calls. User#24403 69 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Player = game.Players.LocalPlayer
Character = Player.Character
x = script.Parent.Value.Value
script.Parent.MouseButton1Click:Connect(function ()
    Character.Head.BrickColor = x
    Character["Right Upper Arm"].BrickColor = x
    Character["Right Lower Arm"].BrickColor = x
    Character["Right Hand"].BrickColor = x
    Character["Right Upper Leg"].BrickColor = x
    Character["Right Lower Leg"].BrickColor = x
    Character["Right Foot"].BrickColor = x
    Character["Lower Torso"].BrickColor = x
    Character["Upper Torso"].BrickColor = x
    Character["Left Upper Arm"].BrickColor = x
    Character["Left Lower Arm"].BrickColor = x
    Character["Left Hand"].BrickColor = x
    Character["Left Upper Leg"].BrickColor = x
    Character["Left Lower Leg"].BrickColor = x
    Character["Left Foot"].BrickColor = x


end)

Don't use parenthesis to Index.

0
omg thank you Hizzaa -3 — 5y
0
This code can be shortened for the good, by using loops User#24403 69 — 5y
Ad
Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

This is actually a way more efficient way of going about changing BodyColors, this method is also Universal so it'll work for both R15 and R6

Also, you shouldn't name Values by it's own name, so for this transaction, also judging by the use for Color3 or BrickColor replacement, we're going to call it 'Color', following the MouseButton1Click event, it must be a TextButton, we'll call this 'GuiButton'

Color should also only be the BrickColor name, Eg. "Lime green", not "BrickColor("Lime green")"

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Color = script:FindFirstAncestor("Color").Value
local GuiButton = script.Parent
GuiButton.MouseButton1Click:Connect(function()
   if (Character) then
      local CharacterParts = Character:GetChildren()
      local BodyParts = {}
      for _,BodyPart in ipairs(CharacterParts) do
         if (BodyPart:IsA("BasePart") and BodyPart.Name ~= "HumanoidRootPart") then
            table.insert(BodyParts, BodyPart)
         end
      end
      for i = 1,#BodyParts do
         BodyParts[i].BrickColor = BrickColor.new(Color)
      end
   end
end)

Answer this question