-
What do I want? Well I want a custom leaderboard, as well as the playerTag colors being the same as the ones in the default chat system (Note: I’m trying to make the 2007 Leaderboard).
-
The problem? I didn’t want the player names blank white, and wanted to give it color, just like how it was in the old leaderboard based on archive evidence.
-
What did I do about it? I added a color pallete and asked AI to do the job for me, but since it’s AI, the job was unsuccessful.
After that, I remembered a phrase from someone about humans being smarter than AI, so I went to the Dev Forums so that I can probably get my solution.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local leaderboardFrame = script.Parent
local playerListTemplate = ReplicatedStorage:WaitForChild("UI"):WaitForChild("PlayerListContainer")
local NameColors = {
BrickColor.new('Bright red'),
BrickColor.new('Bright blue'),
BrickColor.new('Earth green'),
BrickColor.new('Bright violet'),
BrickColor.new('Bright orange'),
BrickColor.new('Bright yellow'),
BrickColor.new('Light reddish violet'),
BrickColor.new('Brick yellow')
}
-- Get a leaderstat value
local function getLeaderstat(player, statName)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local stat = leaderstats:FindFirstChild(statName)
if stat and stat:IsA("IntValue") then
return stat.Value
end
end
return 0
end
-- Get a color for the player's name based on their name value
local function getPlayerChatColor(player)
local name = player.Name
local hash = 0
for i = 1, #name do
hash = hash + string.byte(name, i)
end
local colorIndex = (hash % #NameColors) + 1
return NameColors[colorIndex].Color
end
-- Refresh the leaderboard UI
local function refreshLeaderboard()
-- Clear old entries
for _, child in ipairs(leaderboardFrame:GetChildren()) do
if child:IsA("Frame") and child.Name:find("_Entry") then
child:Destroy()
end
end
-- Create an entry for each player
for _, player in ipairs(Players:GetPlayers()) do
local entry = playerListTemplate:Clone()
entry.Name = player.Name .. "_Entry"
-- Username label
local usernameLabel = entry:WaitForChild("FriendLabel"):WaitForChild("PlayerName")
if usernameLabel then
usernameLabel.Text = player.Name
usernameLabel.TextColor3 = getPlayerChatColor(player)
end
-- Tix label
local tixLabel = entry:FindFirstChild("Labels"):FindFirstChild("Tix")
if tixLabel then
tixLabel.Text = tostring(getLeaderstat(player, "Tix"))
end
-- Level label
local levelLabel = entry:FindFirstChild("Labels"):WaitForChild("Level")
if levelLabel then
levelLabel.Text = tostring(getLeaderstat(player, "Level"))
end
entry.Parent = leaderboardFrame
end
end
-- Listen for updates
local function watchPlayer(player)
-- Refresh when team changes
player:GetPropertyChangedSignal("Team"):Connect(refreshLeaderboard)
-- Watch leaderstats
player.ChildAdded:Connect(function(child)
if child.Name == "leaderstats" then
child.ChildAdded:Connect(function(stat)
if stat:IsA("IntValue") then
stat:GetPropertyChangedSignal("Value"):Connect(refreshLeaderboard)
end
end)
for _, stat in ipairs(child:GetChildren()) do
if stat:IsA("IntValue") then
stat:GetPropertyChangedSignal("Value"):Connect(refreshLeaderboard)
end
end
end
end)
-- If leaderstats already exist
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
for _, stat in ipairs(leaderstats:GetChildren()) do
if stat:IsA("IntValue") then
stat:GetPropertyChangedSignal("Value"):Connect(refreshLeaderboard)
end
end
end
end
-- Hook events
Players.PlayerAdded:Connect(function(player)
watchPlayer(player)
refreshLeaderboard()
end)
Players.PlayerRemoving:Connect(refreshLeaderboard)
-- Start watching existing players
for _, player in ipairs(Players:GetPlayers()) do
watchPlayer(player)
end
refreshLeaderboard()
Edit: Here’s reference on what I’m trying to make (This is part of a script by the Classicblox kit):
local NameColors = {
BrickColor.new('Bright red'),
BrickColor.new('Bright blue'),
BrickColor.new('Earth green'),
BrickColor.new('Bright violet'),
BrickColor.new('Bright orange'),
BrickColor.new('Bright yellow'),
BrickColor.new('Light reddish violet'),
BrickColor.new('Brick yellow')
}
local GetNameValue
local function GetNameValue(Name)
local Length = #Name
local Value = 0
for Index = 1, Length do
local CharacterValue = string.byte(string.sub(Name, Index, Index))
local ReverseIndex = Length - Index + 1
if Length % 2 == 1 then
ReverseIndex = ReverseIndex - 1
end
if ReverseIndex % 4 >= 2 then
CharacterValue = -CharacterValue
end
Value = Value + CharacterValue
end
return Value % 8
end
local function GetChatColor(Name)
return NameColors[GetNameValue(Name) + 1]
end
local LastLabel
for v = 1, 20 do
local Label = Instance.new('TextLabel', List)
Label.Name = 'Label'..v
Label.BackgroundColor3 = Color3.new(163 / 255, 163 / 255, 163 / 255)
Label.BackgroundTransparency = 0.3
Label.BorderSizePixel = 0
Label.Size = UDim2.new(0, 250, 0, 20)
Label.Visible = false
Label.Font = 'Cartoon'
Label.FontSize = 'Size14'
Label.TextColor3 = Color3.new(1, 1, 1)
Label.TextXAlignment = 'Left'
if LastLabel == nil then
Label.Position = UDim2.new(0, 71, 0, 0)
LastLabel = Label
else
Label.Position = LastLabel.Position + UDim2.new(0, 0, 0, 20)
LastLabel = Label
end
end
local Player = {}
local Players = Game:GetService('Players'):GetChildren()
local function UpdateList()
local Labels = List:GetChildren()
for Index = 1, #Labels do
if Labels[Index]:IsA('TextLabel') then
Labels[Index].Visible = false
end
end
for Index = 1, #Player do
Label = List:FindFirstChild('Label'..tostring(Index))
if Label then
Label.Visible = true
Label.Text = Player[Index].Name
Label.TextColor3 = GetChatColor(Player[Index].Name).Color
end
end
end
Any help would be appreciated!