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

How do you use BodyColors in scripts?

local player = game.Players.LocalPlayer
while not player.Character do
    wait()
end
local character = player.Character
local colors = character.BodyColors

if colors then
colors.HeadColor = BrickColor.new(1)
colors.LeftArmColor = BrickColor.new(1)
colors.RightArmColor = BrickColor.new(1)
colors.TorsoColor = BrickColor.new(1)
colors.LeftLegColor = BrickColor.new(1)
colors.RightLegColor = BrickColor.new(1)
end 

How would I access BodyColors? In Play Solo, it's Body Colors, not BodyColors, but I can't write down Body Colors in the script without getting this error:

18:39:50.013 - Players.Player1.PlayerGui.Characters:8: '=' expected near 'if'

2 comments

1

Use FindFirstChild("Body Colors") whenever you need to search for something with a space in its name.

1

Oh thank you, I am sort of new to some of this stuff.

2 answers

✓ Accepted answer

One thing i noticed is that you spelled wrong... Body Colors are spaced.

local colors = character:findFirstChild("Body Colors")

and for the IF Statement, i don't notice anything wrong, but in case:

if colors ~= nil then

Full Script:

local player = game.Players.LocalPlayer
while not player.Character do
    wait()
end
local character = player.Character
local colors = character:findFirstChild("Body Colors")

if colors ~= nil then
colors.HeadColor = BrickColor.new(1)
colors.LeftArmColor = BrickColor.new(1)
colors.RightArmColor = BrickColor.new(1)
colors.TorsoColor = BrickColor.new(1)
colors.LeftLegColor = BrickColor.new(1)
colors.RightLegColor = BrickColor.new(1)
end 

Hope this helps! Thanks, marcoantoniosantos3

Like deaththerapy said, you can use FindFirstChild if you're not sure if the Object you are trying to access exists or not.

However, there is a method, using square brackets, to access a member with spaces in its name directly:

character["Body Colors"] -- Note that there is no period after 'character'.

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