What is the issue? Script is not even reacting to PlayerAdded function and there are no errors
What solutions have you tried so far? Did you look for solutions on the Developer Hub? No
Script:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
Refresh()
end)
player:GetPropertyChangedSignal("Team"):Connect(function()
Refresh()
end)
end)
function Refresh()
for i,frame in pairs(script.Parent.Frame) do
if frame:IsA("Frame") then
frame:Destroy()
end
end
for i,team in pairs(game.Teams) do
if team:IsA("Team") then
local teamDisplay = script.Template:Clone()
local teamNameDisplay = teamDisplay:FindFirstChild("TeamName")
local teamCountDisplay = teamDisplay:FindFirstChild("Count")
teamCountDisplay.Text = tostring(GetCountPlayersInTeam(team))
teamNameDisplay.Text = team.Name
teamNameDisplay.TextColor = BrickColor.new(team.TeamColor)
teamDisplay.Parent = script.Parent.Frame
end
end
end
function GetCountPlayersInTeam(team)
local count = 0
for i,_ in pairs(game.Players) do
if _:IsA("Player") then
if _.Team == team then
count = count + 1
end
end
end
return count
end
function Refresh()
for i,frame in pairs(script.Parent.Frame:GetChildren()) do
if frame:IsA("Frame") then
frame:Destroy()
end
end
for i,team in pairs(game:GetService("Teams"):GetChildren()) do
if team:IsA("Team") then
local teamDisplay = script.Template:Clone()
local teamNameDisplay = teamDisplay:FindFirstChild("TeamName")
local teamCountDisplay = teamDisplay:FindFirstChild("Count")
teamCountDisplay.Text = tostring(GetCountPlayersInTeam(team))
teamNameDisplay.Text = string.upper(team.Name)
teamNameDisplay.TextColor = team.TeamColor
teamDisplay.Parent = script.Parent.Frame
end
end
end
function GetCountPlayersInTeam(team)
local count = 0
for i,_ in pairs(game:GetService("Players"):GetChildren()) do
if _:IsA("Player") then
if _.Team == team then
count = count + 1
end
end
end
return count
end
game.Players.PlayerAdded:Connect(function(player)
Refresh()
player:GetPropertyChangedSignal("Team"):Connect(function()
Refresh()
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
Refresh()
end)
EDIT: Added some things like refreshing tv on player leave