Randomizing character's torso color

I want to make an easy way to differentiate between players if you are playing with friends but the game doesn’t allow you to have your normal avatar. I’m trying to make it so that when your character spawns, the character’s torso will be assigned a color. I wanted to know if the script I have now is the best way to do it.

local numbers = math.random(1, 6)
if (numbers == 1) then
	script.Parent.Torso.BrickColor = Color3.new(0.745098, 0, 0)
elseif (numbers == 2) then
	script.Parent.Torso.BrickColor = Color3.new(0, 0.807843, 0.807843)
elseif (numbers == 3) then
	script.Parent.Torso.BrickColor = Color3.new(1, 0.501961, 0)
elseif (numbers == 4) then
	script.Parent.Torso.BrickColor = Color3.new(0.286275, 0.792157, 0.278431)
elseif (numbers == 5) then
	script.Parent.Torso.BrickColor = Color3.new(0.909804, 0.886275, 0.215686)
elseif (numbers == 6) then
	script.Parent.Torso.BrickColor = Color3.new(0.360784, 0.105882, 0.486275)
end

The script is a server script just placed within the model of the StarterCharacter.

You should use BrickColor.random(), which automatically generates a random brickcolor.

So your whole code can become one line with just

script.Parent.Torso.BrickColor = BrickColor.random()

1 Like

This script works on a normal part in the workspace, but for my character it doesn’t work.

Use BodyColors instead of Torso.BrickColor. That can help you change the character’s colors.

Thank you! At first it wasn’t working but I put the script inside StarterCharacterScripts instead of it being inside the StarterCharacter model. I do have a question though, does the script need to be a server script in order for other players to see the color?

Yes. LocalScripts makes it visible only for the client so I think you should use ServerScripts for all the players to see the color.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.