What I want is to have a global datastore for a leaderboard, but there is an issue, when I do :GetCurrentPage() it returns nothing
local Players = game:GetService("Players")
local Data_Service = game:GetService("DataStoreService")
local Employee_Of_Month = Data_Service:GetDataStore("Employee_Of_Month")
Players.PlayerAdded:Connect(function(player)
local TimeSpent = Instance.new("NumberValue")
TimeSpent.Name = "TimeSpent"
TimeSpent.Parent = player
local oltimer = 0
local s,f = pcall(function()
oltimer = Employee_Of_Month:GetAsync(player.UserId)
if oltimer == nil then
oltimer = 0
end
end)
TimeSpent.Value = oltimer
if not s then warn(f) end task.spawn(function()
while task.wait(1) and TimeSpent ~= nil do
TimeSpent.Value += 1
end
end)
end)
Players.PlayerRemoving:Connect(function(player)
local s,f = pcall(function()
Employee_Of_Month:SetAsync(player.UserId,player:FindFirstChild("TimeSpent").Value)
print('saved')
end)
if not s then warn(f) end
end)
function Get_N_1()
local Employee_Of_Month_List = Data_Service:GetOrderedDataStore("Employee_Of_Month")
local Employee_data = Employee_Of_Month_List:GetSortedAsync(false,10)
local Page = Employee_data:GetCurrentPage()
print(table.unpack(Page))
for Pos,data in pairs(Page) do
local person = data.Key
print(data.Value)
end
end
task.spawn(function()
while wait(5) do
Get_N_1()
end
end)
--[[
function reset_every_week(starting_point)
repeat task.wait() until time() - starting_point > 1000 --(one week = 1000igs)
end
task.spawn(function()
local highest = -1
local highestplayer = nil
while task.wait(1) do
for i, v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild('TimeSpent').Value > highest then
highest = v:FindFirstChild('TimeSpent').Value
highestplayer = v
end
end
local thumb = game.Players:GetUserThumbnailAsync(
highestplayer.UserId,
Enum.ThumbnailType.AvatarBust,
Enum.ThumbnailSize.Size420x420
)
script.Parent.Texture = thumb
script.Parent.Parent.SurfaceGui["Player Name"].Text = highestplayer.Name
local starting_point = time()
reset_every_week(starting_point)
end
end)[[]]
I think it will work like this, you need to use ipairs() instead of pairs() :
function Get_N_1()
local Employee_Of_Month_List = Data_Service:GetOrderedDataStore("Employee_Of_Month")
local Employee_data = Employee_Of_Month_List:GetSortedAsync(false,10)
local Page = Employee_data:GetCurrentPage()
print(Page)
for Pos,data in ipairs(Page) do
local person = data.Key
print(data.Value)
end
end
You’re not saving the data to the ordered data store. You’re saving it to Data_Service:GetDataStore("Employee_Of_Month")
This line you had here is where you SetAsync into: local Employee_Of_Month_List = Data_Service:GetOrderedDataStore("Employee_Of_Month")
Your Employee_Of_Month_List and Employee_Of_Month are two separate DataStores. iirc you can’t SetAsync into :GetDataStore() and expect it to appear in :GetOrderedDataStore() (even if the names are the same).