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

math.random is rounding my numbers, is there a way to get mixed numbers?

I'm using math.random() to add values between 1.99 and 3.99 to player.leaderstats.Dollars.Value. However, when using math.random() the numbers were randomized, but came out as integers. Here's the code I first attempted to do this with:

client.leaderstats.Dollars.Value = client.leaderstats.Dollars.Value + math.random(1.99, 3.99)

When I realized that the numbers were being rounded, I added 2 "NumberValue" objects to the script (so... script.min, and script.max). "script.min.Value" was equal to 1.99, and "script.max.Value" was set to 3.99. Here's what I tried:

client.leaderstats.Dollars.Value = client.leaderstats.Dollars.Value + math.random(script.min.Value, script.max.Value)

The numbers were still being rounded to integers. How would I go about fixing this?

3 comments

0

Multiply math.random() by max, and then clamp it by min. Example: math.clamp(math.random()*3.99, 1.99, math.huge)

0

What does math.clamp() do?

0

clamps a number between min and max. args: n, min, max. if n is less than min, it becomes min. if it is greater than max, it becomes max. otherwise, it returns n.

2 answers

✓ Accepted answer

You could just do a random value between 199 cents and 399 Cents and then convert it to Dollars

 Cents = math.random(199, 399)
 Dollars =  Cents/100 
 client.leaderstats.Dollars.Value = client.leaderstats.Dollars.Value + Dollars

2 comments

0

this one works

0

That's clever. Thx

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