Obby Leaderboard Issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Have a working leaderboard system

  2. 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)

  3. 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

1 Like

Let me test it and then I will help you
(I will test how the code works, I know that I need ui but uh I dont)

1 Like

You need the ui?

if so:

image

I don’t really need, I can make my own (Why studio opened on my screen 4 times in a row when I was typing this)

1 Like

Ah Ok :+1:

some words for roblox

You can remake into your ui


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]]
1 Like

The data.key should contain player’s User ID for it to work properly

1 Like

Yes I know that your was working but not cloning properly

I gave you an example with starter gui
(That is cloning properly)
(And clearing)

1 Like

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)

1 Like

Oh I found where was your mistake I think

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)

1 Like

Got back and wow that is alot of stuff you did!

I will use the scripts you gave and see if it works.

But what was the error in the orginal script? because one fix and i wont have to redo everything.

Anyways Thanks alot!

2 Likes

But what was the error in the orginal script?

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)

1 Like

Removing it wont do anything exepct now empty frames called RowTemplate are showing up.
Fixing the name now.

tryna get the leaderboard working, and then i will improve it from then on

Removing it wont do anything exepct now empty frames called RowTemplate are showing up.

What do you mean by that

1 Like

You can see that things called β€œbase” will show up and doing the rowtemplate destroy thing fixes that

Video:


I well have no problems with thing I made
(You can ignore the unknown user error since its prob deleted ones)

1 Like

I will use yours then. Really hoping it will work (most likely will)


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

1 Like

Wait yours is a gui? I was hoping for a SurfaceGUI? could i drag the contents of the ui into the surfacegui?

ps: if not that is ok, just rather surface

You can make it on surface gui, you will just have to change path’s to templates and etc

1 Like