I’m having trouble creating a leaderboard system that displays players dancing on a podium. Something in the code isn’t working and I cant figure out what it is. (It also isn’t outputting any errors)
It is also worth noting that there are two of these leaderboards in-game, which is why there are two values for the leaderstats.
leaderboards:
Code:
local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local cashDataStore = dataStoreService:GetDataStore("cashDatabase")
local winsDataStore = dataStoreService:GetDataStore("winsDatabase")
local cashLeaderboard = dataStoreService:GetOrderedDataStore("cashLeaderboard")
local winsLeaderboard = dataStoreService:GetOrderedDataStore("winsLeaderboard")
players.PlayerRemoving:Connect(function(player)
local cashValue = player.leaderstats.Cash.Value
local winsValue = player.leaderstats.Wins.Value
cashLeaderboard:SetAsync(player.UserId, cashValue)
winsLeaderboard:SetAsync(player.UserId, winsValue)
end)
function format(value)
local formatted = tostring(value)
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", "%1,%2")
if k == 0 then
break
end
end
return formatted
end
coroutine.wrap(function()
while true do
local cashResults = cashLeaderboard:GetSortedAsync(false, 3, 1):GetCurrentPage()
for i, v in ipairs(cashResults) do
local userId = v.key
local rank = tostring(i)
local value = v.value
local playerName = players:GetNameFromUserIdAsync(userId)
local place = workspace.Lobby.DancingLeaderboard.TopCashPlayers:FindFirstChild(rank)
if place then
place.Statue.Humanoid:ApplyDescription(players:GetHumanoidDescriptionFromUserId(userId))
local anim
pcall(function()
anim = place.Statue.Humanoid.Animator:LoadAnimation(place.Statue.Animation)
end)
anim:Play()
local formatted = format(value)
place.Stats.BillboardGui.Frame.PlayerName.Text = "#" .. rank .. ": " .. playerName
place.Stats.BillboardGui.Frame.MoneyAmount.Text = "Cash: " .. formatted
end
end
local winsResults = winsLeaderboard:GetSortedAsync(false, 3, 1):GetCurrentPage()
for i, v in ipairs(winsResults) do
local userId = v.key
local rank = tostring(i)
local value = v.value
local playerName = players:GetNameFromUserIdAsync(userId)
local place = workspace.Lobby.DancingLeaderboard2.TopWinsPlayers:FindFirstChild(rank)
if place then
place.Statue.Humanoid:ApplyDescription(players:GetHumanoidDescriptionFromUserId(userId))
local anim
pcall(function()
anim = place.Statue.Humanoid.Animator:LoadAnimation(place.Statue.Animation)
end)
anim:Play()
local formatted = format(value)
place.Stats.BillboardGui.Frame.PlayerName.Text = "#" .. rank .. ": " .. playerName
place.Stats.BillboardGui.Frame.WinsAmount.Text = "Wins: " .. formatted
end
end
wait(60)
end
end)