Randomizing decimals (money system) glitches

For the past few days I’ve been trying to make a money system where it adds money whenever you complete certain tasks, and stuff like that.

But, as you can see in the screenshots, things go wrong like:
image
image

Here is my code:

local reward = tonumber(tostring(math.random(15,35)).. "." .. tostring(math.random(0,9)) .. ""..tostring(math.random(1,9)))
game.ReplicatedStorage.ChangeMoney:FireServer(reward,false)

I know that this is definitely not the most efficient method, but I’ve tried others and they’ve given me the same results.
For example, I followed this on how to randomize decimals, but it has given the same results and sometimes glitches out.

Now, I’m going to clarify my money system.
Basically you do something like walking a dog, or delivery, then it adds money to the money value in a player in another localscript, it listens to the money value using getpropertychangedsignal, and sets the gui as the money value.
I literally have no clue why my code isn’t working.

In what range do you want the numbers to generate?

15-35.
The decimals are random from 0-9.

You could do

local reward = math.random(150, 359) / 10

And when you want to display it do

gui.Text = string.format("%.1f", reward)
1 Like

It only works with the tenths decimal.

I tried

math.random(1500, 3599) / 100

But sometimes it prints out only the tenths place? Also, I don’t think this is the most efficient/bug proof method.
image

1 Like

use string.sub() it should work

I think what you’ve got there is perfect for getting the number you need.

It only shows 29.7 because 29.7 == 29.70 and by default numbers don’t show trailing zeroes.

If you want to make it always show 2 decimal places then you can do:

local formattedMoney = string.format(“%.2f”, 29.7) 

print(formattedMoney) -- 29.70