Hey, I’m trying to make it so that the player in the leaderboard goes under their team, and if another player joins, they go under that player, etc, just how the roblox leaderboard works.
Here is my current code. The teams work are are auto created nicely, but I have no idea how to properly position the player.
Here is my code.
local Players = game:GetService("Players");
local Teams = game:GetService("Teams");
local TextService = game:GetService("TextService");
local MainScroll = script.Parent.MainScroll
local TeamTemplate = script.Parent.MainScroll.Templates.Character
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
function PopulateTeams()
for i,v in pairs(MainScroll:GetChildren()) do
if v:IsA("TextLabel") and v.Name == "Character" then
v:Destroy()
end
end
for _, team in ipairs(Teams:GetTeams()) do
local plrs = team:GetPlayers()
if #plrs >= 1 then
local cloned = TeamTemplate:Clone()
cloned.Text = team.Name
cloned.Back.Text = team.Name
cloned.Parent = MainScroll
cloned.Color.ImageColor3 = team.TeamColor.Color
cloned.LayoutOrder = #MainScroll:GetChildren()
cloned.Visible = true
end
end
end
function PopulatePlayers()
for i,v in pairs(MainScroll:GetChildren()) do
if v:IsA("TextLabel") and v.Name == "Player" then
v:Destroy()
end
end
for i,v in pairs(Players:GetChildren()) do
local PlayerTemplate = script.Parent.MainScroll.Templates.Player
local playercloned = PlayerTemplate:Clone()
local playerteam = v.Team
playercloned.PlayerName.Text = v.Name
playercloned.Parent = MainScroll
-- playercloned.LayoutOrder = ?
playercloned.Visible = true
end
end
for i,v in pairs(Teams:GetTeams()) do
v.PlayerAdded:Connect(PopulateTeams)
v.PlayerAdded:Connect(PopulatePlayers)
v.PlayerRemoved:Connect(PopulateTeams)
v.PlayerRemoved:Connect(PopulatePlayers)
end