my global leaderboard has been working fine for a long long time but suddenly it stopped working. I found out that it doesn’t record the name of the players anymore (though not always, I’ve seen that it does sometimes work only one time ‘stops after refresh’ at the start when I join the game). The scipt below here:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("YumsSave2")
local MainFrame = script.Parent.Parent
local RefreshRate = 4
local num = 0
local function RefreshLeaderboard()
for i, Player in pairs(game.Players:GetChildren()) do
DataStore:SetAsync(Player.UserId, Player.leaderstats.Yums.Value)
end
local success, Error = pcall(function()
local success2, Error2 = pcall(function()
local Data = DataStore:GetSortedAsync(false, 77)
local CreditsPage = Data:GetCurrentPage()
end)
if Error2 then
RefreshLeaderboard()
end
local Data = DataStore:GetSortedAsync(false, 75)
local CreditsPage = Data:GetCurrentPage()
for Rank, SavedData in ipairs(CreditsPage) do
if tonumber(SavedData.key) >= 0 then
local Username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key)) --doesn't work (doesn't error btw)
local Credits = SavedData.value
--warn(Username)
if Credits then and not script.Parent:FindFirstChild(Username)
local NewSample = script.Sample:Clone()
for i,v in pairs(script.Parent.ScrollingFrame:GetChildren()) do
if v.Name ~= 'UI' then
num += 1
end
end
NewSample.Visible = true
NewSample.Parent = MainFrame.SurfaceGui.ScrollingFrame
NewSample.Name = Username
NewSample.PName.Text = Username
if Credits <= 1000 then
NewSample.Value.Text = Credits.." Yums"
else
if Credits >= 1000 and Credits <= 1000000 then
local num = math.floor(Credits / 1000)
local deci = math.floor(Credits - (num * 1000))
NewSample.Value.Text = (num .."."..math.floor(deci / 100).."K Yums")
else
if Credits >= 1000000 and Credits <= 1000000000 then
local num = math.floor(Credits / 1000000)
local deci = math.floor(Credits - (num * 1000000))
NewSample.Value.Text = (num .."."..math.floor(deci / 100000).."M Yums")
else
if Credits >= 1000000000 and Credits <= 1000000000000 then
local num = math.floor(Credits / 1000000000)
local deci = math.floor(Credits - (num * 1000000000))
NewSample.Value.Text = (num .."."..math.floor(deci / 100000000).."B Yums")
else
if Credits >= 1000000000000 then
local num = math.floor(Credits / 1000000000000)
local deci = math.floor(Credits - (num * 1000000000000))
NewSample.Value.Text = (num .."."..math.floor(deci / 100000000000).."T Yums")
end
end
end
end
end
NewSample.Rank.Text = "#"..num + 1
num = 0
else
end
else
end
end
end)
end
local suc, err = pcall(function()
RefreshLeaderboard()
end)
if err then
print(err)
end
while true do
for i, Frame in pairs(MainFrame.SurfaceGui.ScrollingFrame:GetChildren()) do
if Frame.Name ~= "Sample" and Frame:IsA("Frame") then
Frame:Destroy()
end
end
RefreshLeaderboard()
Rank2 = 1
wait(RefreshRate)
end
ok didn’t know about that btw (used both of them). I will do that and I’II hope that fixes the issue. thanks for your help! if it fixes it I will give you the solution.
I think not 0.1, I also ran in this problem, take like 5 seconds or 10 seconds.
Basically, this is a function with alot of lines of code, so 0.1 is pretty small amount. Just like DataStores, it takes time, and it also have the use of DataStores, so use like 10 or 30 seconds maximum.
I didn’t faced issues actually, I removed alot of unneccessary steps and I knew DataStores takes alot of time, so I gave it a time of like 30 seconds. I also tried doing like 5 seconds, but it can’t work. Basically what happens is it tries to run the code it can in 5 seconds but as it couldn’t load the names, you don’t see the names. Code just goes linewise.
like you said it works now but only loads the data up to 30, 45 players and I have a top 75. is there any way to make it take less time to run the code? @Moneypro456789
I would suggest you to remove some of the pcalls. It isn’t much useful. It can also reduce your time. Remove some unnessecasary code (if any) or just increase the time.
does this code also costs a lot of time? can’t delete this btw bc I need this.
if Credits <= 1000 then
NewSample.Value.Text = Credits.." Yums"
else
if Credits >= 1000 and Credits <= 1000000 then
local num = math.floor(Credits / 1000)
local deci = math.floor(Credits - (num * 1000))
NewSample.Value.Text = (num .."."..math.floor(deci / 100).."K Yums")
else
if Credits >= 1000000 and Credits <= 1000000000 then
local num = math.floor(Credits / 1000000)
local deci = math.floor(Credits - (num * 1000000))
NewSample.Value.Text = (num .."."..math.floor(deci / 100000).."M Yums")
else
if Credits >= 1000000000 and Credits <= 1000000000000 then
local num = math.floor(Credits / 1000000000)
local deci = math.floor(Credits - (num * 1000000000))
NewSample.Value.Text = (num .."."..math.floor(deci / 100000000).."B Yums")
else
if Credits >= 1000000000000 then
local num = math.floor(Credits / 1000000000000)
local deci = math.floor(Credits - (num * 1000000000000))
NewSample.Value.Text = (num .."."..math.floor(deci / 100000000000).."T Yums")
end
end
end
end
end