How do you use decimals in scripting?

Hi! I’m trying to create a script where u get 0.2 money per click but it doesn’t work on decimal points, but when I use a whole number it works. How do I use a decimal?

Did you try doing something like: .2?

What does your script look like?

Edit: @RockyRosso .2 == 0.2

1 Like

clickDetector.MouseClick:Connect(function(player)

local PlayerMoney = player.leaderstats.Money

PlayerMoney.Value += 0.2

end)

I assume money is an IntValue object. NumberValue objects accept numbers with decimals.

4 Likes

Yes, I’m fully aware. I was just thinking that maybe removing the zero might help. :man_shrugging:

EDIT: That probably doesn’t make a difference lol

1 Like

In the Roblox script I tried 0.2

As Pago said, your probably using an int value instance which only accepts whole number values.

1 Like

Is it just me who uses StringValues for numbers ._.
I don’t get the difference other than NumberValues especially being for numbers.
Is it the way the values are stored or something?

1 Like

Yes, it’s probably just you. But if it works, hey it works. xD

Working code is working code.

True true, I made a script the other day and I have no idea to why it works lol

It’s an intvalue is there like a function or something that I can use for decimals?

NumberValue instances hold doubles (decimals).

sorry but I can’t find it there :sweat_smile: how do I use a NumberValue?

Strings don’t have mathematical stuff. For example if you did this:

print("9999999999999999999999999999")

You would output that exactly. However if you did:

print(99999999999999999999999)

It would have something like this (I’m not good at this high of numbers)

999999999999999e12+

String is good for stuff like dialog while number/int is better for proper use like:

local Number1 = 3
local Number2 = 1

print(Number1 + Number2)

If you tried the same but with strings, it would error unless you use tonumber()

The same way you use IntValues, they just store decimals. I assume you use some datastore script for the Money value. Inside that script, you have to replace the IntValue with NumberValue.

I tried it and it worked! Thank you so much!

1 Like

If that reply fixed the issue, click the checkbox (:white_check_mark:) button to mark it as the answer.

The value inside of leaderstats might be an integer value, try changing it to a number value and it should work.

Integers are full numbers, e.g. 1,2,3,4,5 etc…

Number values can take any, e.g. 1.2,1.3,1.4,1.5 etc…

Edit: Sorry, I didn’t see that it was already solved as it was not marked.