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

Why won't my torso color change when I load the game?

I'm making a game where which team you are on represent your torso colour. My code is here:

game.Workspace.ChildAdded:connect(function(plr)

local team = game:GetService("Teams")

local Orange = game.Teams.Orange

local Blue = game.Teams.Blue

if plr.team == Orange then print('Orange team') local bodycolors = Instance.new("BodyColors", plr) bodycolors.TorsoColor = BrickColor.new("Bright orange") end

if plr.team == Blue then print('Blue team') local bodycolors = Instance.new("BodyColors", plr) bodycolors.TorsoColor = BrickColor.new("Bright blue") end
end)

could you help me fix this

1 comment

0

Psst use the lua blue circle button to help you format your code.

1 answer

There are only three things we will want to address.

  1. When a player joins, we will want to use the PlayerAdded event not the Workspace:ChildAdded. That would only fire when things are added to the Workspace, like parts, NOT players.

  2. We don't actually need to connect to the TeamsService if you don't want to because of the TeamColor property of the Player. We can actually set the BrickColor in that property right into the BodyColors object (the if statements were a good idea, but we can skip them). This is nit-picking on my part and you can keep your if statements if you think that is the right choice.

  3. When we create a new instance of BodyColors, you parent it to the player, this needs to be parented to the character. We can actually use another method to do this. LoadCharacterAppearance.

Here's what your code looks like with those changes.

game.Players.PlayerAdded:connect(function(plr)
   plr.CharacterAdded:Connect(function()
      local bodycolors = Instance.new("BodyColors")
      bodycolors.TorsoColor = plr.TeamColor -- Here's where your if statement logic was.
      plr:LoadCharacterAppearance(bodycolors)
   end)
end)

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