So I have a leaderboard working but its just that my name keeps duplicating and I don’t want it to do that I just want my name on the leaderboard once…
Here’s a vid to explain more:
local leaderboardDataStore = dataStoreService:GetOrderedDataStore("leaderboardDataStore")
local leaderboadPart = workspace.leaderboards.Leaderboard:WaitForChild("MainPart")
local RefreshNum = 5
script.Parent.Gui:Clone()
local function refresh()
for i, Player in pairs(game.Players:GetChildren()) do
leaderboardDataStore:SetAsync(Player.UserId, Player.leaderstats.Cash.Value)
end
local suc, err = pcall(function()
local data = leaderboardDataStore:GetSortedAsync(false, 10)
local CashPage = data:GetCurrentPage()
for Rank, SavedData in pairs(CashPage) do
local Username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
local Cash = SavedData.value
if Cash then
local NewSample = script.Parent.Gui:Clone()
NewSample.Visible = true
NewSample.Parent = leaderboadPart.SurfaceGui.Background
NewSample.Name = Username
NewSample.Rank.Text = "#"..Rank
NewSample.Username.Text = Username
NewSample.Value.Text = Cash
end
end
end)
if not suc then
warn(err)
end
end
while wait() do
refresh()
print("Leaderboard has been updated")
wait(RefreshNum)
end
to clear all the names and fully refresh. Full script:
local leaderboardDataStore = dataStoreService:GetOrderedDataStore("leaderboardDataStore")
local leaderboadPart = workspace.leaderboards.Leaderboard:WaitForChild("MainPart")
local RefreshNum = 5
script.Parent.Gui:Clone()
local function refresh()
leaderboadPart.SurfaceGui.Background:ClearAllChildren()
for i, Player in pairs(game.Players:GetChildren()) do
leaderboardDataStore:SetAsync(Player.UserId, Player.leaderstats.Cash.Value)
end
local suc, err = pcall(function()
local data = leaderboardDataStore:GetSortedAsync(false, 10)
local CashPage = data:GetCurrentPage()
for Rank, SavedData in pairs(CashPage) do
local Username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
local Cash = SavedData.value
if Cash then
local NewSample = script.Parent.Gui:Clone()
NewSample.Visible = true
NewSample.Parent = leaderboadPart.SurfaceGui.Background
NewSample.Name = Username
NewSample.Rank.Text = "#"..Rank
NewSample.Username.Text = Username
NewSample.Value.Text = Cash
end
end
end)
if not suc then
warn(err)
end
end
while wait() do
refresh()
print("Leaderboard has been updated")
wait(RefreshNum)
end
ALright if I DIdN’T EXplAIn RIght after doing that I got this error:
Gui is not a valid member of Frame “Workspace.leaderboards.Leaderboard.MainPart.SurfaceGui.Background”
And if you want the new script here:
local leaderboardDataStore = dataStoreService:GetOrderedDataStore("leaderboardDataStore")
local leaderboadPart = workspace.leaderboards.Leaderboard:WaitForChild("MainPart")
local RefreshNum = 15
local function refresh()
for i, v in pairs(script.Parent:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
for i, Player in pairs(game.Players:GetChildren()) do
leaderboardDataStore:SetAsync(Player.UserId, Player.leaderstats.Cash.Value)
end
local suc, err = pcall(function()
local data = leaderboardDataStore:GetSortedAsync(false, 10)
local CashPage = data:GetCurrentPage()
for Rank, SavedData in pairs(CashPage) do
local Username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
local Cash = SavedData.value
if Cash then
local NewSample = script.Parent.Gui:Clone()
NewSample.Visible = true
NewSample.Parent = leaderboadPart.SurfaceGui.Background
NewSample.Name = Username
NewSample.Rank.Text = "#"..Rank
NewSample.Username.Text = Username
NewSample.Value.Text = Cash
end
end
end)
if not suc then
warn(err)
end
end
while wait() do
refresh()
print("Leaderboard has been updated")
wait(RefreshNum)
end