Team Detection - Not Changing State

Hi Everyone!

For a recent commision, I’ve had to have a billboard gui display your rank in a group based on a certain team. I’ve had it detect the player’s team but once I change the team, it still thinks the player is on the team it was on before. Any Ideas?

EDIT: I’ve also tried this on some of my other team detection scripts and I’ve tried changing the team through the server. I still get the same issue.

1 Like

My go-to with these types of overhead displays is using a Player.CharacterAdded event. That way every time the Player is respawned the display is updated.

However, if you’re changing their team without respawning them, this setup will not work. Would hooking a Team.Changed event work?

Example:

game.Players.PlayerAdded:Connect(function(Player)
Player.Team.Changed:Connect(function()
Player.Character.Head:FindFirstChild(“BillboardGui”).Team.Text = tostring(Player.Team)
end)
end)

Apologies if the formatting is a bit off, I’m on mobile.

1 Like

I havent had any luck with Team.Changed
Any other ideas?

Team.Changed is not a valid event since Team is a Team Value and not an Instance, what you want to use is
player:GetPropertyChangedSignal(“Team”):Connect

Can you post the script here? Can’t give any feedback if you show nothing.

game.Players.PlayerAdded:Connect(function(player)
	game.Players.PlayerAdded:Connect(function(Player)
			print(player.Team.Name)
			Player.Team.Changed:Connect(function()
				local character = player.Character 
				print(player.Team.Name)
				if player.Team == game.Teams.Prisoner then
					character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://903178177"
					character:WaitForChild("Pants").PantsTemplate = "rbxassetid://910550209"
				elseif player.Team == game.Teams.Police then
					character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://167130500"
					character:WaitForChild("Pants").PantsTemplate = "rbxassetid://167130523"
				else
					
				end			
		end)
	end)
end)

Changed fires for objects, not properties: if the Team property changes, it will fire the Changed event for the Player, not their team. You can correct this, as some mentioned earlier up, by using GetPropertyChangedSignal(“Team”) against the player. This’ll also make it so that you’re only making the function get called when Team changes rather than anything else of the player.

Player.Team.Changed:Connect -- Changes this to the below
Player:GetPropertyChangedSignal("Team"):Connect