The coding seems correct, however it refuses to work in game, I tested it in a baseplate and it somehow worked but the scripts are exactly the same in both the baseplate and game.
This script is supposed to list the players points on a global leaderboard as a GUI.
local ODS = game:GetService("DataStoreService"):GetOrderedDataStore("Points")
local Pages = ODS:GetSortedAsync(false,10)
local Data = Pages:GetCurrentPage()
local GUI = game.StarterGui.LeaderboardUI
game.Players.PlayerAdded:Connect(function(plr)
local New = Instance.new("Folder")
New.Name = "leaderstats"
New.Parent = plr
local Stage = Instance.new("NumberValue")
Stage.Name = "Stage"
Stage.Parent = New
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Stage = plr.leaderstats.Points
if Stage then
ODS:IncrementAsync(plr.Name,Stage.Value)
end
end)
local function Update()
local succ,err = pcall(function()
local Template = GUI.Template
for i,v in pairs(GUI.MainFrame:GetChildren())do
if v:IsA("Frame") then
v:Destroy()
end
end
for a,k in pairs(Data)do
local PlayerName = k.key
local PlayerStage = k.value
local NewTemp = Template:Clone()
NewTemp.Name = PlayerName
NewTemp.FrameName.Text = PlayerName
NewTemp.FrameValue.Text = PlayerStage
NewTemp.Visible = true
NewTemp.Parent = GUI.MainFrame
end
end)
if err then
warn("An error has occured when trying to update the leaderboard: " .. err)
end
end
Update()
spawn(function()
while wait(60*3) do
Update()
end
end)
What could be causing this? Please help!

2 comments
The server and client need to talk, add a remote event. You could also add a remote event and clone the script to the players backpack from PlayerGui
Wait() should NOT be a condition.