Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a Win/Loss Ratio/Stat??

I am making a game kinda like deathrun, and I need a script that can use the wins and loses and make them a W/L Ratio?? Can anyone help? And I need the whole thing to save to. How could I use DataPersitance for it??

1 answer

✓ Accepted answer

I can help you with the basic math for this problem. So, you have wins, and losses. Let's say that the player has won 5 times, and lost 20 times. We can find the ratio by dividing 5 by 20. This gives us 0.25, which is the ratio. So the code would look something like this:

WinLossRatio = wins / losses

Now, we are still presented with an issue, for example, let's say a player has lost 7 times and won 2 times. If we do the math for this issue, it comes up with 0.28571428571, that is a bit long. In this case, we will need to round the number.

function round(WinLossRatio, 2)    --First argument is the number, so we'd put WinLossRatio. The second argument is decimal, so we'd put it what decimal place we want the number rounded to. 
 decimal=decimal or 0
 local mult=10^decimal
 return math.floor(number*mult+.5)/mult
end

This discussion is preserved as it was. New answers, comments, and votes are closed.