How do I make a ratio?

Hey guys. I’m making a ratio GUI which will show my games likes and dislikes. Issue is I cant seem to get the ratio for the GUI. I have tried likes/dislikes and it just returns inf probably because dislikes are 0. Please help!

CODE SNIPPET

	local likes = 1 --// Hard codded likes
	local dislikes = 0 --// Hard codded dislikes
	likes = tonumber(likes)
	dislikes = tonumber(dislikes)
	
	local ratio = likes/dislikes
	print(ratio) --// Returns INF

WHAT I WANT IT TO LOOK LIKE


WHAT IT LOOKS LIKE

1 Like

Youre probably just going to have to hard code in a ratio value in the case that dislikes are 0

2 Likes

To find out how much space a ratio should take up, divide the ratio by the total.
Because there is 1 like and 0 dislikes, the total is 1 (1 + 0 = 1). 1 ÷ 1 gives you 1, which when used as a scale value in a UDim2, will cover up the entire bar.

Some other examples:
5 likes, 2 dislikes → 5 + 2 = 7, 5 ÷ 7 = ~0.7 or around 70% of the bar
25 likes, 50 dislikes → 25 + 50 = 75, 25 ÷ 75 = ~0.33, or around 33% of the bar

4 Likes