How'd I convert this progress count to a percentage?

Okay so, I have a loading screen, with a count the shows how many things that are loaded, and the total that should be loaded.

Here’s what it’s like:

Here’s the script for it:

script.Parent:RemoveDefaultLoadingScreen()

local loadingScreen = script.ScreenGui
local plr = game.Players.LocalPlayer


--local cutSceneScript = game:GetService("ReplicatedStorage").CutsceneScript

loadingScreen.Parent = game.Players.LocalPlayer.PlayerGui

local contentProvider = game:GetService("ContentProvider")

game.Loaded:Wait()

local toLoad = workspace:GetDescendants()
local total = #toLoad
for i,v in pairs(toLoad) do
	
	loadingScreen.Background.Counter.Text = "Loading: " .. i .. "/" .. total
	loadingScreen.Background.BarBG.Bar.Size = UDim2.new(i/total, 0, 1, 0)
	contentProvider:PreloadAsync({v})
end

-- Finished loading

wait(1)

print("Removing loading screen..")

local clientLoadedEvent = game:GetService("ReplicatedStorage"):WaitForChild("Events").ClientLoaded

clientLoadedEvent:FireServer(plr)

loadingScreen.Background:TweenPosition(UDim2.new(0, 0, 0, 2000), Enum.EasingDirection.Out, Enum.EasingStyle.Quint)

local gui = plr.PlayerGui:WaitForChild("MenuGUI")

gui.Enabled = true

wait(1)
loadingScreen:Destroy()

How could I possibly convert that count to a percentage? I’d like to do this, as a percentage would look better, and easier to understand how much there is to load.

Yes, for anyone wondering, I did use a small loading script I found, and I then modified it a ton.

Numerator/100/denominator will give u the percentage loaded

example = 50/100 = 50 x 100/100 = 50%

Could you give an example how I’d implement this?

bruh just take this^^
and use the same math like below

loadingScreen.Background.Counter.Text = "Loading: " .. i/total*100 .. "%"
1 Like

This does work, I’m just curious how I’d remove all the decimals after the number. I know that in Python, you can just convert it to a int value, but I’m not sure what to do in Lua.

Oh well I use

math.floor(number+0.5)

this also rounds up, but you can get rid of the point 5 if you just want to remove the decimals I think there are a couple other ways like

string.format("%.0f",number)
1 Like

This works perfectly, thanks for the help!