So basically, I was making a math.random script for a gui, but I want it to be in scale and not offset, so I wanted to add a decimal point to the math.random script. So, I decided to try adding one to the number, but I always get an error and I keep doing it wrong. How could I add a decimal point to a number inside a script.
You can instead use the call math.random() (with no arguments) to generate a number in the range of [0, 1). You can also just divide the result by 10 or 100 or whatever number you please. For instance
That’s not how math.random works with two parameters. math.random only generates integers when you call it with 1 or 2 arguments, so those will just get rounded down. You’re pretty much just calling math.random(0, 0), which will just generate 0s.
If you want to generate a “decimal” number within an interval, I would recommend using the Random object
local r = Random.new()
print(r:NextNumber(0, 10)) -- 6.5671190270581
print(r:NextNumber(0, 10)) -- 8.6838278457998
print(r:NextNumber(0, 10)) -- 3.1862607605153
print(r:NextNumber(0, 10)) -- 9.6170438609961
-- ... you get the idea. It only prints decimal numbers between 0 and 10