ScaledRatio returns as "nan"

while true do
	for _, plr in pairs(game.Players:GetPlayers()) do
		local CorrectResponses = plr.CorrectResponses.Value
		local IncorrectResponses = plr.IncorrectResponses.Value
		local TotalResponses = CorrectResponses + IncorrectResponses
		local Accuracy = (CorrectResponses / TotalResponses) * 100
		local minRatio = 1.0
		local maxRatio = 6.0
		local Ratio = CorrectResponses / (IncorrectResponses + CorrectResponses)
		local ScaledRatio = minRatio + Ratio * (maxRatio - minRatio)
		plr.leaderstats.Accuracy.Value = Accuracy
		if plr.leaderstats.Ratio.Value > 0 then
			plr.leaderstats.Ratio.Value = math.floor(ScaledRatio * factor + 0.5) / factor
		if plr.leaderstats.Accuracy.Value < 60 then
			plr.leaderstats.Rank.Value = "Learner"
			for Rank, Data in pairs(AccuracyToRank) do
				if math.clamp(plr.leaderstats.Accuracy.Value,Data[1],Data[2]) == plr.leaderstats.Accuracy.Value then
					plr.leaderstats.Rank.Value = Rank

The scaledratio changes to something after the player gets a correct answer but it should stay at 1 if there is no correct answers

Easy way to figure out what the issue is would be to put a print statement right before calculating ScaledRatio.

print(CorrectResponses, IncorrectResponses, TotalResponses, Ratio, minRatio, maxRatio)

That way you can see if the values are what you expect and see what is causing the calculation issue.

You may be doing 0/0 as the player hasn’t answered any questions yet. Just do local ScaledRatio = minRatio + Ratio * (maxRatio - minRatio) or 1 to set it to 1 if the first equation returns nan

well isnt the code supposed to set it to 1 when the min is 1

i did the or 1 but it still returns nan

Since nan is not a number any number added to it doesn’t change it
Sorry for that typo I forgot that nan still returns as a true value which doesn’t work with or, try to do a check if ScaledRatio is nan:

if ScaledRatio ~= ScaledRatio then -- if it's nan then it weirdly won't equal to itself
ScaledRatio = minRatio

ok then how can i make the code then limit the ratio to 6.0

You can use math.min:

ScaledRatio = math.min(maxRatio, ScaledRatio) -- returns the smallest number between arguments