--[[ if your changing the DataStore name from LB 
		to anything else you should change it inside the saving script too
	]]
--
local LeaderBoardStore = DataStore:GetOrderedDataStore("LB")


local function Arrange()
	-- pcall can help us to indentify and silence the errors
	
	local success , errormessage = pcall(function()
		
		local MainPage = LeaderBoardStore:GetSortedAsync(false , 50)
		local ThisPage = MainPage:GetCurrentPage()

		for i , v in pairs(ThisPage) do  
			-- i is the player's rank and v is the player's data

			local Player = game.Players:GetPlayerByUserId(v.key)
			local Coins = v.Value or 0 

			local NewFrame = script:FindFirstChild("Frame"):Clone()
			NewFrame.Player.Text = Player.Name
			NewFrame.Rank.Text = i
			NewFrame.Coins.Text = Coins
			NewFrame.Parent = script.Parent
			
			
			if ChatService then -- first checking if ChatService has loaded or not
				-- Leaderboard tags are added in the below lines
				local Speaker = ChatService:GetSpeaker(Player.Name)
				if Speaker then
					-- You can Change the TagText and TagColor
					Speaker:SetExtraData("Tags" , {{TagText = "#"..i  , TagColor = Color3.fromRGB(0, 255, 127)}})
				end
			end

		end
	end)
	
	if not success then
		-- if there is any error in the script it will warn us here
		warn(errormessage)
	end
	
end

Arrange()
