Team Overhead Gui

Hello, I am new to forum and I need help with an code. I am basically new to scripting and I need help with script that doesn’t work.
When I do run game and I am on team like for example : Rose, it does not show that tag.
Can you guys tell me what’s wrong with the script?

local serverstorage = game:GetService("ServerStorage")

function CharacterAdded(character)
         local gui = serverstorage.BillboardGui:Clone()
         gui.TextLabel.Text = player.Team.Name
         gui.TextLabel.TextColor3 = player.Team.TeamColor.Color
         gui.Parent = character.Head
end)

game.Players.PlayerAdded:Connect(function(player)
         player.CharacterAdded:Connect(CharacterAdded)

         if player.Character then
               CharacterAdded(player.Character)
        end
end)

I hope someone can help me!

2 Likes

I believe the problem here is that the script is being run after a player has already joined, meaning they won’t get picked up by the PlayerAdded event.

It is good practice to have your PlayerAdded code in a function rather than directly in the event, and then also make sure to run it on any players already in the game.

local serverstorage = game:GetService("ServerStorage")
local players = game:GetService("Players")

function PlayerAdded(player)
	local function CharacterAdded(character)
		local gui = serverstorage.BillboardGui:Clone()
		gui.TextLabel.Text = player.Team.Name
		gui.TextLabel.TextColor3 = player.Team.TeamColor.Color
		gui.Parent = character:WaitForChild("Head")
	end

	player.CharacterAdded:Connect(CharacterAdded)
	if player.Character then
		CharacterAdded(player.Character)
	end
end

for _, player in pairs(players:GetPlayers()) do
	PlayerAdded(player)
end
players.PlayerAdded:Connect(PlayerAdded)
3 Likes

I do still have problem with it…

1 Like

Team colors use brick colors not Color3 values

1 Like

Try re-pasting the script I posted above. I made a small mistake but it is now fixed.

Additionally, check the Output window in studio (or developer console in-game by pressing F9) and let us know if there are any errors.

As I said, Team colors use brick colors, not Color3 values

Looks like the error is coming from somewhere other than the lines you provided.

Try re-pasting my script again. I have made the necessary fix.

The problem was that you had a ) character after an end which was not necessary because it was a standalone function.

@JollyGameCrazy The script’s color line should work fine, as it is grabbing the Color3 value from the BrickColor value.

I don’t think that’s possible

It is. You can do BrickColor.Color to get a Color3 value from the BrickColor.

1 Like

Oh my bad, thanks for correcting me.

Alright, so the current problem has to do with your BillboardGui. It does not have a TextLabel in it, even though the script is expecting it to have one.

Make sure there is a TextLabel named “TextLabel” inside the BillboardGui.

TextLabel was named Tag. I think that is the problem right?

Yes. Either rename it to TextLabel or change any references to TextLabel in the script to Tag.

I’m surprised I missed that issue too. Re-paste my script above and it should work :crossed_fingers:

The issue this time is that your CharacterAdded function was relying on a player object that it did not have access to. I moved the function into the PlayerAdded function so that it has proper access.

I do still have problem with billboard as you can see, is there any way to fix it?

That is a problem with the StudsOffset property on the BillboardGui object, not a scripting issue. You can make modifications to it until it is offset on the correct axis. (Something around 0, 2, 0 should be good)

1 Like