I’m just simply trying to make these TextLabels (which are inside of BillboardGUIs which are located in every player’s character’s head) show on everyone who is on YOUR team. (So you can see where your teammates are across the map). They don’t show for the other team(s) though. I also want it to constantly update incase a player switches teams or something. Please help! I’ve tried so many things. Here’s my LocalScript which is inside of StarterPlayerScripts:
local players = game:GetService("Players")
local player = players.LocalPlayer
local playercharacters
local function AddTags()
for _, v in pairs(players:GetPlayers()) do
if v.Team == player.Team then
playercharacters = game.Workspace:FindFirstChild(v.Name)
if playercharacters then
local head = playercharacters:WaitForChild("Head")
if head then
local teamTag = head:WaitForChild("TeamTag") -- billboardGUI
if teamTag then
local arrow = teamTag:WaitForChild("Arrow") -- Text label
if arrow then
arrow.Visible = true
else
warn("Arrow not found for player: " .. v.Name)
end
else
warn("TeamTag not found for player: " .. v.Name)
end
else
warn("Head not found for player: " .. v.Name)
end
end
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
if plr == player then
AddTags()
end
plr.CharacterAdded:Connect(function(char)
if plr == player then
AddTags()
end
end)
end)
Here ya go! It’s kind of spaced weird because I typed this out instead of coding it. But what you did wrong was, formatting. It was formatted kind of wonky, tell me how it goes…
local players = game:GetService("Players")
local player = players.LocalPlayer
local playercharacters
local function AddTags(plr, char)
local head = char:WaitForChild("Head")
local teamTag = head:WaitForChild("TeamTag")
local arrow = teamTag:WaitForChild("Arrow")
if not arrow then
warn("No arrow found!")
end
if not teamTag then
warn("No teamTag found!")
end
if not head then
warn("No head found!")
end
if plr.Team == player.Team then
arrow.Visible = true
else
arrow.Visible = false
end
end
for _, v in pairs(players:GetPlayers()) do --Scans to see all current players in the game when the local player joins
local scannedChar = game.Workspace:WaitForChild(v.Name)
if v.Name ~= player.Name then
AddTags(v, scannedChar)
end
end
game.Players.PlayerAdded:Connect(function(plr) --Continues to find the teams of new players joining
plr.CharacterAdded:Connect(function(char)
AddTags(plr, char)
end)
end)
local players = game:GetService("Players")
local player = players.LocalPlayer
local function updateTagVisibility(plr)
local character = plr.Character or plr.CharacterAdded:Wait()
local head = character:WaitForChild("Head", 5) -- Add a timeout to avoid infinite waits
if not head then return end
local teamTag = head:FindFirstChild("TeamTag")
if not teamTag then return end
local arrow = teamTag:FindFirstChild("Arrow")
if not arrow then return end
if plr.Team == player.Team then
arrow.Visible = true
else
arrow.Visible = false
end
end
local function onPlayerAdded(plr)
plr.CharacterAdded:Connect(function(character)
updateTagVisibility(plr)
end)
plr:GetPropertyChangedSignal("Team"):Connect(function()
if plr.Character then
updateTagVisibility(plr)
end
end)
end
for _, otherPlayer in ipairs(players:GetPlayers()) do
if otherPlayer ~= player then
onPlayerAdded(otherPlayer)
if otherPlayer.Character then
updateTagVisibility(otherPlayer)
end
end
end
players.PlayerAdded:Connect(onPlayerAdded)