Duplicating textlabel problem

Hello,

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)
1 Like

It’s duplicating because you are cloning the text. If you are using :Clone() you should make the old one not visible.

You did not understand, I will show you.

https://gyazo.com/cfcde7207865a49d85a5d2d338260e48

Not sure if this works, but try using something like

Add a code where it counts the amount of players currently in team above loop function.

local n = (amt of players in team)

Try to create a code that collects the amount of players that exist in team. Then add a subtracting formula like this under the looping function

n=n-1

then you can try to use that value for repeat end.

repeat wait() until n==0

task.wait() should be used instead.

repeat task.wait() until n == 0
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.

Odd … you’re using a for next loop but in the video it just keeps going …
How many times is this getting fired.

Look at the if after the loop.

Change

if not ValueInArray(contentCitizen:GetChildren(), "1.1 "..player.Name) then

To

if not contentCitizen:FindFirstChild("1.1 "..player.Name) then

It’s the same thing and it does not work because it was this before.

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.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.