Help changing character color if on team

Did you figure it out, im home now if you need help.

i did but maybe if you want to you can send your script so i can try it out

Currently working script:

– // Script Made by DARKMASTER6906 // –

–// Services
local Players = game:GetService(“Players”)
local TM = game:GetService(“Teams”)

–// Tables
local conn = {} --this should prevent memory leaks

–// Functions
local function playerAdded(Player)
conn[Player] = {}

conn[Player][#conn[Player] + 1] = Player.CharacterAdded:Connect(function(Char)
	repeat wait() until Char:FindFirstChild("Humanoid") and Char:FindFirstChild("Body Colors")

	local TeamColor = Player.Team.TeamColor
	local BodyColors = Char:FindFirstChild("Body Colors")

	for i, part in pairs(Char:GetChildren()) do
		if part:IsA("BasePart") then
			part.BrickColor = TeamColor
			print(part.BrickColor)
		end
	end

	BodyColors.HeadColor = TeamColor
	BodyColors.LeftArmColor = TeamColor
	BodyColors.LeftLegColor = TeamColor
	BodyColors.RightArmColor = TeamColor
	BodyColors.RightLegColor = TeamColor
	BodyColors.TorsoColor = TeamColor
end)

end

for i, team in pairs(TM:GetChildren()) do
team.PlayerAdded:Connect(playerAdded)
end

–// This disconnects that character function when the player leaves the game
Players.PlayerRemoving:Connect(function(Player)
for i, connect in pairs(conn[Player]) do
connect:Disconnect()
conn[Player][i] = nil
if #conn[Player] <= 0 then
conn[Player] = nil
end
end
end)

I would just use that script if its working for you.

I swear, you dont know how to read

PlayerAdded:
:Connect( func (player: Player) -> ()): RBXScriptConnection

player: Player means that there is a Player Argument
: RBXScriptConnection means that it returns a signal.

one question for @darkvrn how do i make it so only certain parts of the body are blue and is it visible for other players

maybe you know it @qurxts ?

script in replies
[credits: @darkvrn ]

– // Script Made by DARKMASTER6906 // –

–// Services
local Players = game:GetService(“Players”)
local TM = game:GetService(“Teams”)

–// Tables
local conn = {} --this should prevent memory leaks

–// Functions
local function playerAdded(Player)
conn[Player] = {}

conn[Player][#conn[Player] + 1] = Player.CharacterAdded:Connect(function(Char)
	repeat wait() until Char:FindFirstChild("Humanoid") and Char:FindFirstChild("Body Colors")

	local TeamColor = Player.Team.TeamColor
	local BodyColors = Char:FindFirstChild("Body Colors")

	for i, part in pairs(Char:GetChildren()) do
		if part:IsA("BasePart") then
			part.BrickColor = TeamColor
			print(part.BrickColor)
		end
	end

	BodyColors.HeadColor = TeamColor
	BodyColors.LeftArmColor = TeamColor
	BodyColors.LeftLegColor = TeamColor
	BodyColors.RightArmColor = TeamColor
	BodyColors.RightLegColor = TeamColor
	BodyColors.TorsoColor = TeamColor
end)

end

for i, team in pairs(TM:GetChildren()) do
team.PlayerAdded:Connect(playerAdded)
end

–// This disconnects that character function when the player leaves the game
Players.PlayerRemoving:Connect(function(Player)
for i, connect in pairs(conn[Player]) do
connect:Disconnect()
conn[Player][i] = nil
if #conn[Player] <= 0 then
conn[Player] = nil
end
end
end)

Maybe I know what? What are you needing help with?

how i can change only certain body parts [torso]
and is it visible for other players?

We can use a table to store the names of parts that we want colored
we then check if the part has that name and color it
then you must remove what ever parts you dont want colored from the BodyColors section of the code and keep what you do want colored

And yes, it is visible to others as its on the server

-- // Script Made by DARKMASTER6906 // --

--// Services
local Players = game:GetService("Players")
local TM = game:GetService("Teams")

--// Tables
local conn = {} --this should prevent memory leaks
local WhitelistedParts = {
	
	"Head",
	"Torso",
	"LeftLeg"
	
}

--// Functions
local function playerAdded(Player)
	conn[Player] = {}
	
	conn[Player][#conn[Player] + 1] = Player.CharacterAdded:Connect(function(Char)
		repeat wait() until Char:FindFirstChild("Humanoid") and Char:FindFirstChild("Body Colors")
		
		local TeamColor = Player.Team.TeamColor
		local BodyColors = Char:FindFirstChild("Body Colors")
		
		for i, part in pairs(Char:GetChildren()) do
			if part:IsA("BasePart") and table.find(WhitelistedParts, part.Name) then
				part.BrickColor = TeamColor
			end
		end
		
		--// Remove what parts dont need coloring and keep what does
		BodyColors.HeadColor = TeamColor
		BodyColors.LeftLegColor = TeamColor
		BodyColors.TorsoColor = TeamColor
	end)
end

for i, team in pairs(TM:GetChildren()) do
	team.PlayerAdded:Connect(playerAdded)
end

--// This disconnects that character function when the player leaves the game
Players.PlayerRemoving:Connect(function(Player)
	for i, connect in pairs(conn[Player]) do
		connect:Disconnect()
		conn[Player][i] = nil
		if #conn[Player] <= 0 then
			conn[Player] = nil
		end
	end
end)

thank you so much for your help

and the others that helped!

1 Like

Yeah, so after testing, you can just do:

Blacklist = {"Head"}

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		
		task.delay(1, function() -- delays for 1 second
				for i,v in chr:GetChildren() do --
				    if v:IsA("BasePart") and not table.find(Blacklist, v.Name) then
					v.BrickColor = plr.TeamColor
				end
				
			end
		end)
	
		
	end)
end)

Which would make most of @darkvrn effectively useless, ServerScriptService can handle all of this, StarterCharacterScripts wouldn’t be as efficient

1 Like

thank you for your help but i figured out how to do it

have a great day

you didn’t, he other guy did. you don’t seem to understand how the scripts work so dont say that you did when he did.

alright i will try yours wait a second

Screenshot_7

you removed the bottom end).

oh im sorry did not see that i will try it out rn

this seems to work fine can you explain a bit why the other one had to be so long and this super short and does almost exactly the same?

Mine is longer as it has a connection disconnector to prevent any memory leaks from the CharacterAdded, I made game.Players and a few other things variables and I made it so theres lines of code for the BodyColors as that can override the body parts based on when stuff is loaded

His script waits for the bodycolors the load first before changes body parts colors to prevent this override. The issue with his version is lag may last longer than the 1 second his script stalls for and would be slower because of that wait

Both scripts should work either way, chose which ever you like

2 Likes