You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Have a working leaderboard system
What is the issue? Include screenshots / videos if possible!
I think is that instead of making a new row its replacing the old one until it reaches me (the last one)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Devfourms and videos
Code:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local obbyTimeStoreOrdered = DataStoreService:GetOrderedDataStore("ObbyTime")
local Data = obbyTimeStoreOrdered:GetSortedAsync(false, 100)
local Page = Data:GetCurrentPage()
for rank, data in ipairs(Page) do
local name = data.key
local obbyTime = data.value
local newRow = script.Base:Clone()
if tonumber(name) > 0 then
newRow.Name = Players:GetNameFromUserIdAsync(name)
end
newRow.PlayerImage.Image = Players:GetUserThumbnailAsync(name, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
newRow.PlayerName.Text = newRow.Name
newRow.TimeLabel.Text = tostring(obbyTime / 10)
newRow.LayoutOrder = -rank
newRow.Parent = script.Parent.SurfaceGui.ScrollingFrame
if newRow.Name == "RowTemplate" then
newRow:Destroy()
end
end
Ok it works (I made it update every 5 secs to test) and clears, then updates
UI:
Local Script Code:
local replStorage = game:GetService("ReplicatedStorage")
local LBEvent = replStorage:WaitForChild("LBEvent")
local ClearLBEvent = replStorage:WaitForChild("LBEventClear")
local frame = script.Parent:WaitForChild("Frame")
local ScrollingFrame = frame:WaitForChild("ScrollingFrame")
local Template = ScrollingFrame:WaitForChild("Template")
Template.Visible = false
LBEvent.OnClientEvent:Connect(function(PlrInfo)
local new = Template:Clone()
local PlrName = game:GetService("Players"):GetNameFromUserIdAsync(PlrInfo.UserId)
if not PlrName then
--PlrName = PlrInfo.UserId -- For test
return
else
PlrName = "@"..PlrName
end
new.Name = PlrName
new:WaitForChild("PlayerName").Text = PlrName
new:WaitForChild("StatValue").Text = PlrInfo.Stat1
new.Visible = true
new.Parent = ScrollingFrame
end)
ClearLBEvent.OnClientEvent:Connect(function()
for i,v in pairs(ScrollingFrame:GetChildren()) do
if v:IsA("Frame") then
if v.Name ~= "Template" then
v:Destroy()
end
end
end
end)
βlbβ script code:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local obbyTimeStoreOrdered = DataStoreService:GetOrderedDataStore("ObbyTime")
local Data = obbyTimeStoreOrdered:GetSortedAsync(false, 100)
local Page = Data:GetCurrentPage()
task.wait(5) -- To testing, also to maybe let players load in, you can use .PlayerAdded event anyway,
-- You can remove this wait if you want, and print too
print("started")
while true do
game:GetService("ReplicatedStorage").LBEventClear:FireAllClients()
task.wait(1) -- U can make this lower or remove I think
for rank, data in ipairs(Page) do
local name = data.key
local obbyTime = data.value
game:GetService("ReplicatedStorage").LBEvent:FireAllClients({
UserId = name,
Stat1 = obbyTime
})
end
task.wait(5) -- CHANGE THIS TO WHATVR U WANT
end
--[[for i=1, 100 do -- this was to get data inside ordered datastore
task.spawn(function()
obbyTimeStoreOrdered:SetAsync("PlayerID"..i, i)
print("Set", i, "PlayerID"..i)
end)
end]]
I know that better solution would be send entire page data to client, but I thought of that too late
(server looping throuigh pages, then sending player the userid and stat data)
if newRow.Name == "RowTemplate" then
newRow:Destroy()
end
You are never changing name of it I think
If that is issue then I made that thing for nothing, but I never tried making global leaderboards, so good to try that)
(Actually you change it, but I guess it doesnβt changes, so that is causing problem)
I guess its the name of frame doesnβt changes,
try removing the :Destroy() thing and see if it wont destroy, if it wont then try fixing the name not being set
(Also better to create all the frames on client)
Also if you want i can rework it a bit so server sends full page data
For this error to not appear, it will take a time to load (A bit), but it wont show up