-- July 23 2022
--By @IAmBanFor
local leaderboard = script.Parent:WaitForChild("leaderboard")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ChatColor = require(script:WaitForChild("ChatColor"))
local y = 20
local x = 0
local teamlabelX = {}
leaderboard.Size += UDim2.new(0,0,0,15)
local function getPlrMatching()
if #Players:GetChildren() < #leaderboard:GetChildren() - 1 then
local players = {}
for i,v in pairs(leaderboard:GetChildren()) do
players[i] = v
end
for i,v in pairs(players) do
if players[i-1] then
if players[i-1].Text == v.Text then
players[i-1]:Destroy()
v.Position -= UDim2.new(0,0,0,20)
leaderboard.Size -= UDim2.new(0,0,0,20)
else
for _,a in pairs(players) do
if a.Text == v.Text then
a:Destroy()
v.Position -= UDim2.new(0,0,0,20)
leaderboard.Size -= UDim2.new(0,0,0,20)
end
end
end
else
for _,a in pairs(players) do
if a.Text == v.Text then
a:Destroy()
v.Position -= UDim2.new(0,0,0,20)
leaderboard.Size -= UDim2.new(0,0,0,20)
end
end
end
end
end
end
local function AddLSName(teamName)
x += 155 - #teamlabelX
local LSLabel = script:WaitForChild("LSLabel"):Clone()
LSLabel.Position = UDim2.new(0,x,0.036,0)
LSLabel.Text = teamName
LSLabel.Parent = leaderboard
table.insert(teamlabelX, #teamlabelX + 1, x)
print(x, teamlabelX[teamName])
leaderboard.Position -= UDim2.new(0,100,0,0)
leaderboard.Size += UDim2.new(0,100,0,0)
end
local function AddLScore(playerName, teamName, score)
if leaderboard:FindFirstChild(playerName) then
local ScoreLabel = script:WaitForChild("ScoreLabel"):Clone()
ScoreLabel.Position = UDim2.new(0,teamlabelX[teamName],0,leaderboard:FindFirstChild(playerName).Position.Y.Offset + 5)
ScoreLabel.Text = score
ScoreLabel.Parent = leaderboard
else
print("Can't be found because does not exist")
end
end
local function OnPlayerAdded(playerName)
local playerLabel = script:WaitForChild("PlayerLabel"):Clone()
playerLabel.Name = playerName
playerLabel.Text = playerName
playerLabel.TextColor3 = ChatColor(playerName)
playerLabel.Parent = leaderboard
playerLabel.Position += UDim2.new(0,0,0,y)
leaderboard.Size += UDim2.new(0,0,0,20)
y += 20
end
local function OnPlayedLeft(playerName)
if leaderboard:FindFirstChild(playerName) then
leaderboard:FindFirstChild(playerName):Destroy()
else
print("Can't be deleted because does not exist")
end
end
ReplicatedStorage:WaitForChild("OnPlayerAdded").OnClientEvent:Connect(OnPlayerAdded)
ReplicatedStorage:WaitForChild("AddLSName").OnClientEvent:Connect(AddLSName)
ReplicatedStorage:WaitForChild("AddLScore").OnClientEvent:Connect(AddLScore)