Arithmetic Problem and TextLabel

I am trying to implement a “killer” chance system into my game, but I either end up with an outrageously long figure or 0% with/without using math.round.

Here is my script:

while wait(1) do
	local Players = game.Players.NumPlayers
	if Players >= 2 then
		wait()
		script.Parent.Text = math.round((Players / Players) / Players) * 100 .." %"
	else
		wait()
		script.Parent.Text = math.round((Players / Players) / Players) * 100 .." %"
	end
end

Here are some illustrations of my problem:

Without math.round
RobloxScreenShot20230603_230743636

With math.round
RobloxScreenShot20230603_230930280

Ideally, I would like the value to remain clear for the player to see (e.g., 33.3%).

The issue is probably caused because you are rounding number that would look like this:
(2/2) / 2 = 1 / 2 = 0.5.
0.5 when rounded will be floored aka rounded to 0 resulting in the text being always 0.
You need to round the equation after multiplying it with the 100

try this instead:

script.Parent.Text = math.round(((Players / Players) / Players) * 100) .." %"
1 Like

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