I do not know why but it’s duplicating the text for no reason (I am checking if the label exist already but it does not matter…).
local APModule = require(game:GetService("ServerScriptService").Modules.ManagementAP)
local RankModule = require(game:GetService("ServerScriptService").Modules.ManagementRank)
local rs = game:GetService("ReplicatedStorage")
local Team = game:GetService("Teams")
local function ValueInArray(array, value)
for i,v in pairs(array) do
if v.Name == value then
return true
end
end
return false
end
rs.Events.LeaderboardUI.OnServerEvent:Connect(function(plr)
local leaderboardUI = plr.PlayerGui.Leaderboard
local teams = Team:GetTeams()
for _, team in teams do
local playersInTeam = team:GetPlayers()
if team.TeamColor == BrickColor.new("Medium stone grey") then
local contentCitizen = leaderboardUI.Frame.TitleCitizen.Content.ScrollingFrame
if #playersInTeam > 0 then
if not contentCitizen:FindFirstChild("1.0 Citizen") then
local title = contentCitizen.FORMATTitle:Clone()
title.Name = "1.0 Citizen"
title.TextColor3 = Color3.fromRGB(156, 156, 156)
title.Text = team.Name
title.Visible = true
title.Parent = contentCitizen
end
for index, player in pairs(playersInTeam) do
if not ValueInArray(contentCitizen:GetChildren(), "1.1 "..player.Name) then
local APs = APModule.get(player.UserId)
local Rank = RankModule.get(player.UserId)
local playerLabel = contentCitizen.FORMATPlayer:Clone()
playerLabel.Name = "1.1 "..player.Name
playerLabel.Text = player.Name.." | "..tostring(APs).." AP | "..tostring(Rank)
playerLabel.Visible = true
playerLabel.Parent = contentCitizen
end
end
end
end
end
end)
for index, player in pairs(playersInTeam) do
if not ValueInArray(contentCitizen:GetChildren(), "1.1 "..player.Name) then
local APs = APModule.get(player.UserId)
local Rank = RankModule.get(player.UserId)
local playerLabel = contentCitizen.FORMATPlayer:Clone()
playerLabel.Name = "1.1 "..player.Name
playerLabel.Text = player.Name.." | "..tostring(APs).." AP | "..tostring(Rank)
playerLabel.Visible = true
playerLabel.Parent = contentCitizen
end
end
There is already a loop to check if their is still players.
local APModule = require(game:GetService("ServerScriptService").Modules.ManagementAP)
local RankModule = require(game:GetService("ServerScriptService").Modules.ManagementRank)
local rs = game:GetService("ReplicatedStorage")
local Team = game:GetService("Teams")
rs.Events.LeaderboardUI.OnServerEvent:Connect(function(plr)
local leaderboardUI = plr.PlayerGui.Leaderboard
local teams = Team:GetTeams()
for _, team in teams do
local playersInTeam = team:GetPlayers()
if team.TeamColor == BrickColor.new("Medium stone grey") then
local contentCitizen = leaderboardUI.Frame.TitleCitizen.Content.ScrollingFrame
if #playersInTeam > 0 then
if not contentCitizen:FindFirstChild("1.0 Citizen") then
local title = contentCitizen.FORMATTitle:Clone()
title.Name = "1.0 Citizen"
title.TextColor3 = Color3.fromRGB(156, 156, 156)
title.Text = team.Name
title.Visible = true
title.Parent = contentCitizen
end
for index, player in pairs(playersInTeam) do
local APs = APModule.get(player.UserId)
local Rank = RankModule.get(player.UserId)
if not contentCitizen:FindFirstChild("1.1 "..player.Name) and contentCitizen:FindFirstChild("FORMATPlayer") then
local playerLabel = contentCitizen.FORMATPlayer:Clone()
playerLabel.Name = "1.1 "..player.Name
playerLabel.Text = player.Name.." | "..tostring(APs).." AP | "..tostring(Rank)
playerLabel.Visible = true
playerLabel.Parent = contentCitizen
end
end
end
end
end
end)
So problem came from my modules so I moved them before the condition.