So I made a global leaderboard for kills but now my datastore2 is not working well. I don’t know if I’m doing this right.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("Kills") <---
local gui = script.Parent.Parent
local mainFrame = script.Parent
local List = mainFrame:WaitForChild("List")
local template = script:WaitForChild("Template")
local Board = gui.Parent
local DataStore2 = require(game.ServerScriptService.Saver:WaitForChild("DataStore2"))
local refreashRate = 10 -- seconds
local maxPlayers = 100 -- max players on board
function refreashBoard()
for i, player in ipairs(game.Players:GetPlayers()) do
local CurrencyStore = DataStore2("Kills", player) <---
local value = CurrencyStore:Get()
if value then
local newValue = math.round(value * 1000)
DataStore:SetAsync(player.UserId, newValue)
else
repeat task.wait(0.1)
value = CurrencyStore:Get()
until value ~= nil
end
end
local success, errorMessage = pcall(function()
local data = DataStore:GetSortedAsync(false, maxPlayers)
local page = data:GetCurrentPage()
for rank, saveData in ipairs(page) do
local user = game.Players:GetNameFromUserIdAsync(tonumber(saveData.key))
local currency = saveData.value
if currency then
local newTemplate = template:Clone()
newTemplate.Name = user
newTemplate.Parent = List
end
task.wait(0.1)
end
end)
end
refreashBoard()
while task.wait(refreashRate) do
refreashBoard()
end