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.
I go every thing working but could not figure out how to get the Character
in a Server Script so I got stopped at MostPlayedTag.Parent =
and I wanted to put = Character.Head
but could i did not know how to get the character can anyone help.
Thanks for helping!
Server Script
local DataStoreService = game:GetService("DataStoreService")
local TimeplayedLeaderboard = DataStoreService:GetOrderedDataStore("TimeplayedLeaderboard")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
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
if Rank == 1 then
local MostPlayedTag = ReplicatedStorage.MostPlayedTag:Clone()
MostPlayedTag.Parent =
end
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