Team Color Indicator

So basically my friend made a really cool movement system for my game but the name tags aren’t there anymore so its hard to tell which team someone is on, but it doesn’t seem to want to work, the color just stays as the default circle color.



local Players = game:GetService("Players")

local RunService = game:GetService("RunService")



local function onCharacterAdded(character, plr)

	RunService.Stepped:Wait()
	local billboard = game.ReplicatedStorage.BillboardGui:Clone()
	billboard.Parent = character.Head
	billboard.Enabled = true
--[[	while true do

		if plr.Team == "Taggers" then
			billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
		elseif plr.Team == "Safe" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
		elseif plr.Team == "Survivor" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
		end--]]
	end



game.Players.PlayerAdded:Connect(function(plr) -- Insert your name in between the ""
	plr.CharacterAdded:Connect(onCharacterAdded)
	local Character = plr.CharacterAdded:Wait()	
	local billboard = plr.Character.Head.BillboardGui
	while true do

		if plr.Team == "Taggers" then
			billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
		elseif plr.Team == "Safe" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
		elseif plr.Team == "Survivor" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
		end
	end
	wait(3) -- waits just in case player isn't loaded -- makes it visible

end)



1 Like

Hi!

The problem is likely that plr.Team refers to the team object and not the name. Try using plr.Team.Name instead.

1 Like

Alright so I did that, and I got this error now (the color is still default)
image

1 Like
local Players = game:GetService("Players")

local RunService = game:GetService("RunService")



local function onCharacterAdded(character, plr)

	RunService.Stepped:Wait()
	local billboard = game.ReplicatedStorage.BillboardGui:Clone()
	billboard.Parent = character.Head
	billboard.Enabled = true
--[[	while true do
task.wait()

		if plr.Team == "Taggers" then
			billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
		elseif plr.Team == "Safe" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
		elseif plr.Team == "Survivor" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
		end--]]
	end



game.Players.PlayerAdded:Connect(function(plr) -- Insert your name in between the ""
	plr.CharacterAdded:Connect(onCharacterAdded)
	local Character = plr.CharacterAdded:Wait()	
	local billboard = plr.Character.Head.BillboardGui
	while true do

		if plr.Team == "Taggers" then
			billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
		elseif plr.Team == "Safe" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
		elseif plr.Team == "Survivor" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
		end
	end
	wait(3) -- waits just in case player isn't loaded -- makes it visible

end)
1 Like

The timeout was likely because of the while true do loop. Consider using while wait() do instead.

1 Like

So while using the code from the person above you, and your suggestion, it now doesn’t change the color, but it has no errors.

1 Like

Use print statements

1 Like

What do you mean by print “statement”?

1 Like

Did you also use plr.Team.Name instead of plr.Team? Just making sure.

1 Like

Could’ve sworn I did, I think it reverted. However even after fixing it, the same result happens.

1 Like

Mind resending what you have so far so I can get a better idea?

1 Like
local Players = game:GetService("Players")

local RunService = game:GetService("RunService")



local function onCharacterAdded(character, plr)

	RunService.Stepped:Wait()
	local billboard = game.ReplicatedStorage.BillboardGui:Clone()
	billboard.Parent = character.Head
	billboard.Enabled = true
--[[	while true do
task.wait()

		if plr.Team == "Taggers" then
			billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
		elseif plr.Team == "Safe" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
		elseif plr.Team == "Survivor" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
		end--]]
end



game.Players.PlayerAdded:Connect(function(plr) -- Insert your name in between the ""
	plr.CharacterAdded:Connect(onCharacterAdded)
	local Character = plr.CharacterAdded:Wait()
	local billboard = game.ReplicatedStorage.BillboardGui:Clone()
	billboard.Parent = Character.Head
	while wait() do

		if plr.Team.Name == "Taggers" then
			billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
		elseif plr.Team.Name == "Safe" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
		elseif plr.Team.Name == "Survivor" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
		end
	end
	wait(3) -- waits just in case player isn't loaded -- makes it visible

end)
1 Like

bruh

Ok, I think I got it.
Comment the line plr.CharacterAdded:Connect(onCharacterAdded).
Then, in the same function, after billboard.Parent = Character.Head, write billboard.Enabled = true.

Lemme know if that works.

1 Like

Now the billboardgui just doesnt appear, and there are still no errors.

1 Like

Alright, remove the top function and replace the bottom one with this:

game.Players.PlayerAdded:Connect(function(plr) -- Insert your name in between the ""
	  plr.CharacterAdded:Connect(function(Character)
	local billboard = game.ReplicatedStorage.BillboardGui:Clone()
	billboard.Parent = Character.Head
        billboard.Enabled = true
	while wait() do

		if plr.Team.Name == "Taggers" then
			billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
		elseif plr.Team.Name == "Safe" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
		elseif plr.Team.Name == "Survivor" then
			billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
		end
	end
	end)

end)
1 Like

omg there we go thanks so much

1 Like

Haha, happy to help. Sorry that took so long to figure out.

1 Like

The current solution you have is extraordinarily inefficient. This is because you are using an infinite loop. The player can stay on the same team for a long time, but regardless, this code will continue to run every heartbeat (frame). Roblox has built-in methods which help to solve a problem like this. Rather than loop infinitely checking for the team, set the team initially, and then bind a function to a changed event.

Here is an example:

--Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--Variables
local billboard = ReplicatedStorage:WaitForChild("BillboardGui")

--Functions

--Player Added
local function onPlayerAdded(plr)
	--Definining the function here so it is within the scope to use the plr variable
	local function onCharacterAdded(char)
		local bb = billboard:Clone() --Clone the billboard GUI
		bb.Parent = char --Parenting it to the player's character

		--For changing the billboard color
		local function updateBBColor()
			bb.ImageColor3 = plr.Team.TeamColor.Color or Color3.fromRGB(255, 255, 255) --The team color, or white
		end
		
		--Binding the player's team changing
		plr:GetPropertyChangedSignal("Team"):Connect(updateBBColor)
	end

	--In case the player's character is already loaded
	if plr.Character then
		onCharacterAdded(plr.Character)
	end

	--Binding the character added
	plr.CharacterAdded:Connect(onCharacterAdded)
end

--Events
Players.PlayerAdded:Connect(onPlayerAdded)

Let me know if this does not work, I can make adjustments.

1 Like