This local script is for custom team-only nametags.
TeamNameLabel is a BillboardGui.
LOCAL_TeamTagsDisabled is a custom settings value that disables nametags.
LOCAL_InCutscene checks whether the client is viewing a cutscene so it disables nametags.
How can I optimize this script? I’m pretty sure this causes some performance issues on the client since my game runs with 70 players on a single server.
local plrs = game:GetService("Players");
local lclplr = plrs.LocalPlayer
local rs = game.ReplicatedStorage
local runS = game:GetService("RunService")
runS.Heartbeat:Connect(function()
for i, plr in pairs(plrs:GetPlayers()) do
if plr.Character and plr.Character:FindFirstChild("Head") and plr.Team == lclplr.Team and plr ~= lclplr then
local check = plr.Character.Head:FindFirstChild("TeamNameLabel")
if not check then
local c = script.TeamNameLabel:Clone()
c.Frame.name.TextColor3 = plr.TeamColor.Color
c.Frame.name.Text = plr.Name
c.Frame.Dot.BackgroundColor3 = plr.TeamColor.Color
c.Parent = plr.Character.Head
end
if check then
check.Frame.name.TextColor3 = plr.TeamColor.Color
check.Frame.name.Text = plr.Name
check.Frame.Dot.BackgroundColor3 = plr.TeamColor.Color
if rs.LOCAL_TeamTagsDisabled.Value == true then
check.Enabled = false
else
check.Enabled = true
end
if rs.LOCAL_InCutscene.Value == true then
check.Enabled = false
end
end
end
if plr.Character and plr.Character:FindFirstChild("Head") and plr.Team ~= lclplr.Team then
local check = plr.Character.Head:FindFirstChild("TeamNameLabel")
if check then
check:Destroy()
end
end
end
end)```