Name tag team colour change

Hi, I am trying to make a name tag that changes colour according to whatever team they are on. Let’s say they are on the blue team, their name tag would change to the blue colour. Right now I have the main script that kinda manages the name tag to display the Name of the user, their rank in the group, and what team they are on. Inside the text UI for the team part I have managed to make a local script that changes the colour according to whatever team I am on but the only problem is when I go in team test with other people it only let’s me see my name tags colour change. I will show pictures of my explorer and the setup. This is what is in the local script:

local rank = script.Parent
local Player = game.Players.LocalPlayer

local Color = Player.Team.TeamColor.Color
local R,G,B

R = Color.R * 255
G = Color.G * 255
B = Color.B * 255

rank.TextColor3 = Color3.fromRGB(R,G,B)

Main Script:

local groupID = 13232134

game.Players.PlayerAdded:Connect(function(player)
	local groupRank = player:GetRoleInGroup(groupID)
	local clone = script.Rank:Clone()
	clone.Parent = game.Workspace:WaitForChild(player.Name).Head
	clone.Frame.Name1.Text = player.Name
	clone.Frame.Rank.Text = groupRank
	clone.Frame.Team.Text = player.Team.Name
	
	
	player.CharacterAdded:Connect(function()
		local groupRank = player:GetRoleInGroup(groupID)
		local clone = script.Rank:Clone()
		clone.Parent = game.Workspace:WaitForChild(player.Name).Head
		clone.Frame.Name1.Text = player.Name
		clone.Frame.Rank.Text = groupRank
		clone.Frame.Team.Text = player.Team.Name
	end)


end)

image
Below is an image of what it looks like and what I mean by I can’t see other peoples change colour.

The local script is named Colour changer and the main one is InsRankHandler. All of this is put in ServerScripService. If anyone can figure out why it isn’t making other peoples name tag change that I can see then I would really appreciate some feedback!

1 Like

Change local script to basic script and change this:

local Player = game.Players.PlayerAdded:Wait()
3 Likes

I’m not too good at scripting, but it might be because you tried it in a LocalScript, because with a local script, it only does certain stuff with the player themself, not with others. If I’m correct (probably not tbh), you should try messing around with a normal script and see if some chunks might work in a normal script instead of a local script

3 Likes

I just tried it and it now shows the other users change colour, but when they change teams it doesn’t change the colour of the users new team.

Also i don’t recommend to use this because player name can be same with instance name
Use this instead:

player.CharacterAdded:Connect(function(Character)--Put Character here
clone.Parent = Character:WaitForChild("Head")
2 Likes

Try this code:

local rank = script.Parent
local Player = game.Players.PlayerAdded:Wait()
local Color = Player.Team.TeamColor.Color
local function ChangeTeam()
local R,G,B

R = Color.R * 255
G = Color.G * 255
B = Color.B * 255

rank.TextColor3 = Color3.fromRGB(R,G,B)
end
ChangeTeam()
Player.Team.TeamColor:GetPropertyChangedSignal("Color"):Connect(ChangeTeam)
1 Like

It didn’t work, do you have any other suggestions?

Hello, the issue is because you are doing the color change on the client-side via LocalScript. Changes made on the client do not replicate to the server therefore other players will not be able to see that change. This is due to a security feature roblox added to prevent exploiters from abusing games.

To fix this, simply create a function in your script that changes the UI Color when the Character reloads or gets added. Here’s an example:

local function ChangeUIColor(Player)
   local teamColor = Player.Team.TeamColor.Color;
   local R, G, B = Color.R * 255, Color.G * 255, Color.B * 255;
   
   local playerGui = Player:WaitForChild("PlayerGui");
   local Rank = Rank.Frame.Rank;
   Rank.TextColor3 = Color3.fromRGB(R, G, B);
end;

You can call this with:

ChangeUIColor(Player : Player)

Hope this helps, let me know if there are still issues.

So, would I replace the local script with a regular script and just past your text (The function and the function call) in that script?

Okay so I am unsure on where you want me to put this and the function call, also I did try to do it but no matter how I did it the words color were highlighted and the player in the function call were highlighted.

So this is what I have figured out so far:

So I have changed the local script to a regular script and changed the code to:

local rank = script.Parent
local Player = game.Players.PlayerAdded:Wait()


local Color = Player.Team.TeamColor.Color
local R,G,B

R = Color.R * 255
G = Color.G * 255
B = Color.B * 255

rank.TextColor3 = Color3.fromRGB(R,G,B)

which has helped with making the other users name tag change colour, but the only problem now is that if anyone switches teams the colour doesn’t change. So all I need now is to figure out how to make it so when you change teams the colour changes accordingly.

Not sure if you knew this or not, but you don’t have to semi-colon every statement. It’s also more readable if you don’t!

Yeah, sorry I got used to other language syntax :sweat_smile:

1 Like

You just need to put the function in your regular script and call it whenever it needs to be called

I have 2 regular scripts, the one that holds everything and the one inside the Team textUI, which one does it go and and do I delete anything when I add it in? Also why does the word color highlight when I add it in?

I am still looking for a solution for this.

@JackyssWrld I changed it. Try it now.