local DataStore2 = require(game.ServerScriptService:WaitForChild("MainModule")) local ordered = game:GetService("DataStoreService"):GetOrderedDataStore("points") local function updateLeaderboard() local success, errorMessage = pcall(function() local Data = ordered:GetSortedAsync(false, 5) local WinsPage = Data:GetCurrentPage() for Rank, pointsdata in ipairs(WinsPage) do local player =game.Players local userName = game.Players:GetNameFromUserIdAsync(tonumber(pointsdata.key,player)) local Name = userName local Wins = pointsdata.value local isOnLeaderboard = false for i, v in pairs(game.Workspace.Leaderboard.Base.LS.RankBack:GetChildren()) do if v.Player.Text == Name then isOnLeaderboard = true break end end if isOnLeaderboard == false then local newLbFrame = game.ReplicatedStorage:WaitForChild("Ranks"):Clone() newLbFrame.OneN.Text = Name newLbFrame.OneA.Text = Wins newLbFrame.One.Text = Rank newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.Leaderboard.Base.LS.RankBack:GetChildren()), 0) newLbFrame.Parent = game.Workspace.Leaderboard.Base.LS.RankBack end end end) if not success then print(errorMessage) end end while true do for _, Player in pairs(game.Players:GetPlayers()) do ordered:SetAsync(Player.UserId, Player.leaderstats.IQ.Value) end for _, frame in pairs(game.Workspace.Leaderboard.Base.LS.RankBack:GetChildren()) do frame:Destroy() end updateLeaderboard() print("Updated!") wait(60) end
Using data store 2, saving the data store 2 value into the ordered datastore. Maybe I Messed up somewhere or misunderstood something? I don't know. Please help. Above is the leaderboard script, below will be the data script.
local DataStore2 = require(game.ServerScriptService:WaitForChild("MainModule")) local default = 0 game.Players.PlayerAdded:Connect(function(plr) local pointsdata = DataStore2("points", plr) local leaderstats = Instance.new("Folder",plr) leaderstats.Name = ("leaderstats") local points = Instance.new("NumberValue", leaderstats) points.Name = "IQ" local function pointsupdate (Updatedvalue) points.Value = pointsdata:Get(Updatedvalue) end pointsupdate(default) pointsdata:OnUpdate(pointsupdate) local store = DataStore2("points", plr) store:AfterSave(function(newData) local orderedStore = (points) repeat local s = pcall(orderedStore.SetAsync, orderedStore, plr.UserId, newData) until s end) end)