I have this global leaderboard inside my game that displays the top 10 players with the highest amount of currency in the game (Like Tokens). Aswell as having a DataStore system that saves different In-Game values for each player (Like Gems or EXP). Though it is not working for me...
This is my Global Leaderboard script
local CashODS = game:GetService("DataStoreService"):GetOrderedDataStore("ShowingValues") local function Handler() local Success, Err = pcall(function() local Data = CashODS:GetSortedAsync(false, 5) local CashPage = Data:GetCurrentPage() for Rank, Data in ipairs(CashPage) do local Name = Data.key local Cash = Data.value local NewObj = game.ReplicatedStorage:WaitForChild("lbFrame"):Clone() NewObj.Player.Text = Name NewObj.Cash.Text = Cash NewObj.Rank.Text = "#"..Rank NewObj.Position = UDim2.new(0, 0, NewObj.Position.Y.Scale + (0.09 * #game.Workspace.GlobalLeaderboard.lbGUI.Holder:GetChildren()), 0) NewObj.Parent = game.Workspace.GlobalLeaderboard.lbGUI.Holder end end) if not Success then error(Err) end end while true do wait(60) for _,Player in pairs(game.Players:GetPlayers()) do CashODS:SetAsync(Player.Name, Player.leaderstats.RampTokens.Value) end for _,v in pairs(game.Workspace.GlobalLeaderboard.lbGUI.Holder:GetChildren()) do if v.Name == "lbFrame" then v:Destroy() end end Handler() end
This is my DataStore script
local DS = game:GetService("DataStoreService"):GetDataStore("ShowingValues") game.Players.PlayerAdded:connect(function(player) local key = "key-"..player.userId local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats" --Folder made for storing player values that don't wanna be seen from other players local hiddenstats = Instance.new("Folder", leaderstats) hiddenstats.Name = "hiddenstats" local Level = Instance.new("IntValue", leaderstats) Level.Name = "Level" Level.Value = 1 local RampTokens = Instance.new("IntValue", leaderstats) --Currency I want to show on the Global Leaderboard RampTokens.Name = "RampTokens" RampTokens.Value = 1000 local EXP = Instance.new("IntValue", hiddenstats) EXP.Name = "EXP" EXP.Value = 10 local save = DS:GetAsync(key) if save then EXP.Value = save[1] Level.Value = save[2] EXP.Parent = hiddenstats else local load = {EXP.Value, Level.Value} DS:SetAsync(key,load) end end) game.Players.PlayerRemoving:connect(function(player) local EXP = player.leaderstats.hiddenstats:FindFirstChild("EXP") local Level = player.leaderstats:FindFirstChild("Level") EXP.Parent = player.leaderstats local key = "key-"..player.userId local load = {EXP.Value, Level.Value} print("Doing") DS:SetAsync(key,load) end)
How would I change the scripts so that I would work? Any help appreciated :)