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

How do I make a player's TorsoColor the same as their TeamColor?

I wrote a script that tries to make a player's TorsoColor the same as their TeamColor but it doesn't work.

local players = game:GetService("Players")
players.PlayerAdded:connect(function(p)
	p.CharacterAdded:connect(function(char)
		while true do 
			local TorsoColor = char['Body Colors'].TorsoColor
			local TeamColor = p.TeamColor
			TorsoColor = TeamColor
			print(TorsoColor)
			wait(1)
			print(TeamColor)
		end
	end)
end)

  1. The StarterCharacter I have has all Body Colors as White.
  2. The starting TeamColor is Blue.
  3. Both the output of print(TeamColor) and print(TorsoColor) is Blue.
  4. Changing teams does not change the output of print(TeamColor) and print(TorsoColor).
  5. The color of my player's Torso is still White regardless of what team I'm on.

Does anyone know what the problem is?

2 comments

0

instead of a local variable for torsocolor, try just setting char['BodyColors'].TorsoColor = p.TeamColor since the TorsoColor is a Property, also any shirt or pants templates will override the body appearance

0

I tried doing that first but it didn't work either, also, the StarterCharacter I have for the players doesn't have any clothing.

1 answer

Hello.You have to use a coroutine because the while true do loop will keep on looping and never let it to go on to the rest of the script.

local players = game:GetService("Players")
players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(char)
        coroutine.wrap(function()
	        while true do 
	            local TorsoColor = char['Body Colors'].TorsoColor
	            local TeamColor = p.TeamColor
	            TorsoColor = TeamColor
	        end
	end)()
    end)
end)

Please accept and upvote this answer if it helped.

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