So the other day I decided to make a leaderboard for the amount of time you played and it works .
But now I am wondering if there is a way can get the first 3 people to give them titles.
There is my script down there. (The ReplicatedStorage was just the way of getting the titles but I have not put the titles yet.)
Thanks for helping!
Server Script
local DataStoreService = game:GetService("DataStoreService")
local TimeplayedLeaderboard = DataStoreService:GetOrderedDataStore("TimeplayedLeaderboard")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = TimeplayedLeaderboard:GetSortedAsync(false, 5)
local TimeplayedPage = Data:GetCurrentPage()
for Rank, data in ipairs(TimeplayedPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local TimePlayed = data.value
local isOnLeaderboard = false
for i, v in pairs(game.Workspace.TimePlayedLeaderboard.LeaderboardGui.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
break
end
end
if TimePlayed > 0 and isOnLeaderboard == false then
if Rank <= 10 then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.TimePlayed.Text = TimePlayed.. "m"
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.085 * #game.Workspace.TimePlayedLeaderboard.LeaderboardGui.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.TimePlayedLeaderboard.LeaderboardGui.Holder
end
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
TimeplayedLeaderboard:SetAsync(player.UserId, player.leaderstats.Minutes.Value)
end
for _, frame in pairs(game.Workspace.TimePlayedLeaderboard.LeaderboardGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
wait(60)
end
You can simply just call TimeplayedLeaderboard[1] if ur data store saves the players, if u want the userid then u have to save the userid directly to that datastore
If you want to give the three highest ranked players (1st, 2nd & 3rd) a special rank, you should check that rank.
Something alike underneath (or inside) your if Rank <= 10 then (which I assume only displays the 10 best players
if Rank == 1 then
-- Give them the title. You may want to store a 'BillboardGui' in ServerStorage and :Clone() that to their head, for example.
elseif Rank == 2 then -- And so forth
Keep in mind this title may need to be removed when they get overtaken on the leaderboard, though.
It’s all up to you what the tag ends up looking like. To clone it, you’d do something like:
function giveSpecialTag(tagMessage, tagColour) -- inside the parenthesis are 'parameters' (the received argumens in order)
local tag = game.ServerStorage.Tag
local givenTag = tag:Clone()
givenTag .Name = "RankTag"
givenTag .Parent = player.Character.Head
givenTag .TextLabel.Text = tagMessage
givenTag .TextLabel.TextColor3 = tagColour
end
And add this under the if Rank == 1 then and customise it thrice depending on your content giveSpecialTag("SPECIAL TEXT", Color3.fromRGB(250, 250, 50) ) – These are arguments you pass
NOTE: You may want to refer to the stored tag beforehand
There might be an easier way, but this’d probably work as well.
local player = game.Players:GetPlayerByUserId(tonumber(data.key))
local character = player.Character or game.Workspace[player.Character] -- Not 100% sure if you need to use both
Bro i have the same issue rn like what do i do ;-0. And also when u ask people the question they always give random answers like im trying to get the first plr id like how do i do it.