After doing a tutorial twice, heres the link(Creating Global Leaderboards With GUI!), my global leaderboard still didn’t work. everything in the Gui is right and I got no errors. So I went ahead and tried to use alvin blox his datastore so it would not be a table just a number. But then the datastore jsut didn’t save. But the big problem is the global leaderboard. Can someone please look into it.
Leaderstats:
local DataStore = game:GetService("DataStoreService")
local myDataStore = DataStore:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local luck = Instance.new("NumberValue")
luck.Name = "Luck"
luck.Parent = leaderstats
luck.Value = 0
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-Luck")
end)
if success then
luck.Value = data
else
print("There was an error while giving Player Data.")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
myDataStore:SetAsync(plr.UserId.."-Luck", plr.leaderstats.Luck.Value)
end)
if success then
print("Player Data successfully saved!")
else
print("There was an error while saving Player Data.")
warn(errormessage)
end
end)
ServerSideGlobal leaderboard. I think the problem is at the server side, I’ll have the problem marked in the script, just behind the “Main()” function:
--// SERVICES //--
local Replicated = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService('DataStoreService')
local Players = game:GetService('Players')
--// DATASTORE //--
local DataStore = DataStoreService:GetOrderedDataStore('Test')
--// FOLDER //--
local Folder = Replicated:WaitForChild('Leaderboard') -- YOUR FOLDER IN REPLICATED STORAGE TO KEEP ENTRIES
--// SETTINGS //--
local TotalEntires = 50
local EntriesPerPage = 5
local RefreshTime = 15 -- In Seconds
-- // FUNCTIONS //--
local function updateValue(rank, key, value)
if Folder:FindFirstChild(rank) then
local found = Folder:FindFirstChild(rank)
if found.Key.Value ~= key then
found.Key.Value = key
found.Value.Value = value
end
else
local new = Instance.new('NumberValue', Folder)
new.Name = rank
local newKey = Instance.new('NumberValue',new)
local newValue = Instance.new('NumberValue',new)
newKey.Name = 'Key'
newValue.Name = 'Value'
newKey.Value = key
newValue.Value = value
end
end
local function Main()
local success, pages = pcall(function()
return DataStore:GetSortedAsync(false, EntriesPerPage) -- the script goes here
end)
if success then -- instead of the succes
for i=0,TotalEntires,EntriesPerPage do
local entries = pages:GetCurrentPage()
for rank, entry in pairs(entries) do
updateValue(rank, entry.key, entry.value)
end
if pages.IsFinished then
break
else
pages:AdvanceToNextPageAsync()
end
end
end
end
-- // LOOP // --
while true do
print('Refreshing')
Main()
task.wait(RefreshTime)
end
This is the local script idk if it works because the script never got to run because of the serverscript:
--// SERVICES //--
local Replicated = game:GetService('ReplicatedStorage')
--// FOLDER //--
local Folder = Replicated:WaitForChild("Leaderboard")
--// TEMPLATE //--
local Template = script:WaitForChild("Template")
--// UI //--
local ui = script.Parent
local Main = ui.GlobalLeaderboardFrame
local ScrollingFrame = Main.GlobalLeaderboardScrollingFrame
--// FUNCTIONS // --
local function UpdateEntry(instance : Instance)
if instance:IsA("StringValue") then
local Rank = instance.Name
local Key = instance:FindFirstChild('Key')
local Value = instance:FindFirstChild('Value')
local Values = {Key; Value;}
if ScrollingFrame:FindFirstChild(Rank) then
local found = ScrollingFrame:FindFirstChild(Rank)
found:FindFirstChild('Name').Text = tostring(Key.Value)
found:FindFirstChild('Rank').Text = tostring(Rank)
found:FindFirstChild('Value').Text = tostring(Value.Value)
else
local new = Template:Clone()
new.Parent = ScrollingFrame
new.LayoutOrder = Rank
new:FindFirstChild('Name').Text = tostring(Key.Value)
new:FindFirstChild('Rank').Text = tostring(Rank)
new:FindFirstChild('Value').Text = tostring(Value.Value)
end
for _, v in pairs(Values) do
v.Changed:Connect(function()
UpdateEntry(instance)
end)
end
end
end
local function Set()
for _, item in pairs(Folder:GetChildren()) do
UpdateEntry(item)
end
end
Set()
--// EVENTS // --
Folder.ChildAdded:Connect(UpdateEntry)
Here is a picture of the explorer: