Can someone explain this code?

Sorry for this weird request especially considering the fact that I’ve been scripting for many years but this is really confusing me. I found a tutorial for a global leaderboard and they game me this model and I’m so confused. This is the main script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local data = {}

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"
	
	local Diamonds = Instance.new("IntValue", leaderstats)
	Diamonds.Name = "Stars"
end)

local function addSuffix(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 ds = game:GetService("DataStoreService")

local TapsODS = ds:GetOrderedDataStore("database")

local timeUntilReset = 5
local player

while wait(1) do


	timeUntilReset = timeUntilReset - 1

	script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."


	if timeUntilReset == 0 then

		timeUntilReset = 30


		for i, plr in pairs(game.Players:GetPlayers()) do
			
			--if plr.Name == "" or plr.Name == "" or plr.Name == "" or plr.Name == "" or plr.Name == "" then
				
			--else
			--	TapsODS:SetAsync(plr.UserId, plr.Values.Diamonds.Value)
				
			--end
			
			TapsODS:SetAsync(plr.UserId, plr.leaderstats.Stars.Value)
		end

		for i, leaderboardRank in pairs(script.Parent:GetChildren()) do

			if leaderboardRank.ClassName == "Frame" then
				leaderboardRank:Destroy()
			end
		end
		
		local success, errorMsg = pcall(function()

			local data = TapsODS:GetSortedAsync(false, 25, 1)
			local TapsPage = data:GetCurrentPage()
			
			for rankInLB, dataStored in ipairs(TapsPage) do


				local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
				local Taps = dataStored.value


				local template = script.Template:Clone()

				template.Name = name .. "Leaderboard"

				template.PlrName.Text = name

				template.Rank.Text = "#" .. rankInLB

				template.Taps.Text = addSuffix(tostring(dataStored.value))

				template.Parent = script.Parent
			end			
		end)
	end
end

I’m really confused about addSuffix function, and TapsODS stuff, any help is appreciated. Thanks

addSuffix() just changes a number like 1000 to 1K
as for TapsODS its just an Ordered DataStore (find more about that here)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.