Leaderboard script

Why that?
He needs to wait 60 seconds not run it as fast as possible.

where is my script it says while loop ?

so what is the correct script now ?

If you’re using the same script as me, then it’s either that you’re changing the money via client and server still reads it as a old value or you didn’t wait 60 seconds to update the leaderboard.

Yeah, you right. He didn’t need that fast. But I think IntValue.Changed event is better to track the changed of the “Money”.

No, that’s not what is he trying to do, that wouldn’t respect data store limits.

1 Like

can i change this MoneyX1 to Money?

Yes, but that won’t suddenly make the script work, it’ll just create a new datastore.

it works know but got an problem

how to let it show like 1Qn or somthing

Yeah your numbers are too big, you’re gonna have to make a script that displays them as for example 1M+, 1B+ etc.

can i add that in the same script ?

can u help me with the k m etc

my value is Cash
30 characters

I wrote that a while ago, I’m using it in all of my games, all you have to do is add some more suffixes in a table

local function addSuffix(number)
	number = tonumber(number)
	if number == 1 then return number  end
	local s = {"", "K", "M", "B", "T"}
	local n = 0
	while number >= 1000 do
		number = number / 10^3
		n = n + 1
	end
	local pfx = n >= #s and s[#s] or s[n + 1]
	number = n >= #s and number * 10^((n + 1 - #s) * 3) or math.floor(number * 10) / 10
	return number..pfx
end

print(addSuffix(1200000)) --> 1.2M

if i add this the script breaks

You didn’t do something right then, all you have to do is, paste this function at the top of your code and change this line Frame.Money.Text = tostring(v.value) to Frame.Money.Text = addSuffix(tostring(v.value))

addSuffix has a blue line under it

Can you show me what have you done

local function addPostfix(number)
	number = tonumber(number)
	if number == 1 then return number  end
	local s = {"", "K", "M", "B", "T","Qd","Qn","Sx","Sp","O","N","D"}
	local n = 0
	while number >= 1000 do
		number = number / 10^3
		n = n + 1
	end
	local pfx = n >= #s and s[#s] or s[n + 1]
	number = n >= #s and number * 10^((n + 1 - #s) * 3) or math.floor(number * 10) / 10
	return number..pfx
end

local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("CashX1")

for i = 1,10 do
    local Sam = script.Sample:Clone()
    Sam.Name = i
    Sam.Parent = script.Parent.SurfaceGui.Frame.ScrollingFrame
    Sam.UserPos.Text = "[".. tostring(i) .. "]"
    Sam.Money.Text = "Nil"
    Sam.UserName.Text = ""
    Sam.LayoutOrder = i
    script.Parent.SurfaceGui.Frame.ScrollingFrame.CanvasSize = UDim2.new(0,0,0,50*i)
end

function UpdateGui()
	
	for i,v in pairs(game.Players:GetChildren()) do
		local Data = v:WaitForChild("leaderstats").Cash.Value
		DataStore:SetAsync(v.UserId, Data)
	end
	
	local Pages = DataStore:GetSortedAsync(false,10)
	local Data = Pages:GetCurrentPage()
	
	for k,v in pairs(Data) do
		if tonumber(v.key) >= 1 then
			local Frame = script.Parent.SurfaceGui.Frame.ScrollingFrame:FindFirstChild(tostring(k))
			if Frame then
				Frame.UserName.Text = game.Players:GetNameFromUserIdAsync(v.key)
				Frame.Money.Text = addSuffix(tostring(v.value))
			end
		end
	end

end

while true do 
    UpdateGui()
    wait(60)
end