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

How do you use BodyColors in scripts?

Asked by 9 years ago
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'

1
Use FindFirstChild("Body Colors") whenever you need to search for something with a space in its name. deaththerapy 60 — 9y
1
Oh thank you, I am sort of new to some of this stuff. PancakeChop 35 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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

Ad
Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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

Answer this question