Make a textlabel show the player's team?

I have a TextLabel in my game, it’s supposed to show their team name, and colour

Screenshot:

image

[TEAM] will be changed to, for example

“Visitors” and the TextColor should be changed to Medium stone grey

image

it doesn’t work, here is the part of the script I use to attempt it.

	local frame = ui.Frame
	local name = frame.PlayerName
	local role = frame.Rank
	local team = frame.Team
	local VisitorColour = Color3.fromRGB(163, 162, 165)
	local StudentColour = Color3.fromRGB(248, 248, 248)
	local StaffColour = Color3.fromRGB(13, 105, 172)
	local CouncilColour = Color3.fromRGB(128, 187, 219)
	

	
	
	
	name.Text = Player:GetRoleInGroup(11954854)..", "..Player.Name
	role.Text = pRank
	if role.Text == "Guest" then
		role.Text = "Visitor"
	end
	
		game.Players.PlayerAdded:Connect(function(plr)
		plr.CharacterAdded:Connect(function(chr)
			team.Text = plr.Team
			if plr.Team == "Visitor" then
				team.TextColor3 = VisitorColour
			elseif plr.Team == "Student" then
				team.TextColor3 = StudentColour
			elseif plr.Team == "Staff" then
				team.TextColor3 = StaffColour
			elseif plr.Team == "Council" then
				team.TextColor3 = CouncilColour
			end
		end)
	end)

I get nothing in output, I’ve also tried using the TeamColor property yet it doesn’t work

Try this.

1 Like

this didn’t work unfortunately, here is the code I used

	local Players = game:GetService("Players")
	local Teams = game:GetService("Teams")
game.Players.PlayerAdded:Connect(function(player)
		player.CharacterAdded:Connect(function()
		if player.Team == Teams["Visitors"] then -- add, or Teams["(team name)"] to add more teams to it
			team.Text = "Visitor"
			team.TextColor3 = VisitorColour
		elseif player.Team == Teams["Students"] then
			team.Text = "Students"
			team.TextColor3 = StudentColour
		elseif player.Team == Teams["Staff"] then
			team.Text = "Staff"
			team.TextColor3 = StaffColour
		elseif player.Team == Teams["Council"] then
			team.Text = "Council"
			team.TextColor3 = CouncilColour	
			end
		end)
	end)

You must use plr.Team.Name in order to get the string value for the TextLabel to use.

This didn’t work either

nothing in output, text stayed as Team

These must also be changed to plr.Team.Name

1 Like

You are making your code too complicated. Try this.

team.Text = plr.Team.Name

Just like what Volieb said you must specify the team name the script has to know the name of the team.

I did.

	local Players = game:GetService("Players")
	local Teams = game:GetService("Teams")
	game.Players.PlayerAdded:Connect(function(player)
		player.CharacterAdded:Connect(function()
			wait(3)
			if player.Team.Name == Teams["Visitors"] then
				team.Text = "Visitor"
				team.TextColor3 = VisitorColour
			elseif player.Team.Name == Teams["Students"] then
				team.Text = "Students"
				team.TextColor3 = StudentColour
			elseif player.Team.Name == Teams["Staff"] then
				team.Text = "Staff"
				team.TextColor3 = StaffColour
			elseif player.Team.Name == Teams["Council"] then
				team.Text = "Council"
				team.TextColor3 = CouncilColour	
			end
		end)
	end)

No, this is wrong. You can go back to your original script but just replace the plr.Team with plr.Team.Name

I tried that and it didn’t work

What is the VisitorColour and StudentColour.

Does the player change teams on client or server?

no team change script, it’s just a randomized team. all the teams have AutoAssignable on and it’s just a free for all on who gets what

(for now)
it will be a server script when i can be bothered to script it

Okay, i think the issue is the gui itself, the server doesn’t see it, because the client “cloned” it therefore only “replicating” to the client that cloned it.
Have you made sure the server clones the gui to character head?

WHY ARE YOU CHECKING WHAT IS THE TEAM’S NAME? JUST DO team.Text = player.Team.Name

1 Like

yes… server clones it

it’s a regular script inside serverscriptservice, with the ui inside it.

i know it works because the name and rank are handled through the same script and they work perfectly, just teams are giving me an issue.

because each team has it’s own colour, and i’m showing a colour depending on the team.
my script is not ‘complicated’

You are very frustrating. Why even ask about this stuff if you never listen to ANYBODY. There is so many people with the right awnser but you keep changing the script the wrong way every time.

1 Like

make a normal script INSIDE the billboard gui.

local __PLAYER = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent.Parent) -- first parent is billboardgui, second parent is head and third is character model!
local __TEAMS = game:GetService("Teams")
script.Parent.TextLabelHere.Text == __PLAYER.Team.Name -- make sure it runs in case the player is automatically assigned a team on cloned!
__PLAYER:GetPropertyChangedSignal("TeamColor"):Connect(function()
   if __PLAYER.Team == __TEAMS["whatever"] then
    script.Parent.TextLabelHere.Text = "whatever"
  end
--[[ if you dont want an if statement you can do this
   script.Parent.TextLabelHere.Text == __PLAYER.Team.Name
--]]
end)