I'm horrible at math and need to figure out percentages

I was unsure where to post this but I don’t want my game moderated, so:

I have a table of weighted strings, yeah?

local rates = {

	-- I removed the table after I got the solution

}

And I have this function to determine the outcome:

function m.GenerateRace()
	local TotalWeight = 0

	for i,v in pairs(rates) do
		TotalWeight = TotalWeight + v[2]
	end

	local Chance = math.random(1, TotalWeight)
	local Counter = 0
	
	for i,v in pairs(rates) do
		Counter = Counter + v[2]
		if Chance <= Counter then
			return v[1]
		end
	end
end

I learned that Roblox requires things that the players spend Robux on to have percentages. I don’t know how to calculate the percentages accurately and would really love the help! If there’s any more information needed or I’m just completely wrong, please let me know!

I’ll just use this

Your first system should work fine though.

I didn’t really understand your problem, but for example, if you want to know how much is 25 of 200, apply the formula: (x * 100) / y,
where x = 25 and y = 200.
So, it would be: (25 * 100) / 200 (result = 12.5%).

1 Like