Help with math trouble

I don’t know why it’s saying this but

math.clamp(math.floor(math.random(1,(Player.leaderstats.Suscribers.Value * Player.leaderstats['Video Quality'].Value * SongBenefit))/6),120,300000)

whe nI run this, it says ’ ServerScriptService.Handler:189: invalid argument #2 to ‘random’ (interval is empty)
What does this means?
Can’t understand error

2 Likes

That error happens when the second argument to math.random is smaller than the first.

Player.leaderstats.Suscribers.Value * Player.leaderstats['Video Quality'].Value * SongBenefit

Must be returning a value less than 1 in some cases. Try printing out that value by itself to check.

Question, what about this

math.clamp(math.floor(math.random((Player.leaderstats.Suscribers.Value * Player.leaderstats['Video Quality'].Value * SongBenefit))/6),120,300000)

because this says the same

Any idea what’s causing this?

3

I have seen issues where having a math.random call in-line like that had issues, forgot specifics about it however. You should try moving it to a variable and referencing the variable there. If that doesn’t work, you should try invoking either math.floor or math.ceil on the argument passed.

Additionally, consider switching to the new Random.

No, I have no idea what’s causing it without knowing what the values are in the leaderboards. Print out those values and find the problem.

Still, the same

local hi = (Player.leaderstats.Suscribers.Value * Player.leaderstats['Video Quality'].Value * SongBenefit/6)
print(hi)
	local am = math.clamp(math.random(hi),1,300000)
	print(am)
	am = math.floor(am)
	local cash = math.clamp((am/4),120,200000)

The same error, on ‘cash’…

But what does it print for hi and am?

Also, that is not doing the same math as you originally posted.

The Random class isn’t really new. It existed for quite some time now. And also not so long ago both functionalities have been changed to have the same behaviour, neither is better than the other. I would only go for the Random class if I seriously wanted to have decimals in my number generation (using the :NextNumber() method), which is something the OP doesn’t seem to want in this case, he’s flooring the result anyways.

1 Like

Ah, I really meant more “newer” than “brand new” when I said that. Also, I didn’t know they had merged the functionality of them. Developer Hub seems outdated then, thanks for letting me know.

1 Like