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 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)
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.
I’m surprised I missed that issue too. Re-paste my script above and it should work
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.
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)