Attemp to perfom subtraction on boolean and string *Error*

let’s say I want to access the water price, which is in a module, and I put a print() to check the price

local datamodule= require(game:GetService(“ServerScriptService”).data)
local waterprice = datamodule.stats[“water”].price
print(waterprice)

Output: 50(50 is the water price)

everything is ok, but the problem is that when I subtract a value from the price of water, the “price” becomes a string

local datamodule= require(game:GetService(“ServerScriptService”).stats)
local item_price = datamodule.data[“water”].price
coins.Value = coins.Value -item_price

Output: attempt to perfom arithmetric (sub) on boolean and string
Output: attempt to compare boolean and string

Did you try putting a tonumber() around the water price?

in the module or script variable? did not quite understand

Wherever your performing the subtraction. If the print statement shows a number it’s possible the “number” is a string like this…

“50”

When you really want it as a numerical value.

Replace this with:

local item_price = tonumber(statsmodule.stats[“water”].price)

still gives the error

this is how the water table is

image

and this is how i used tonumber()

Are you showing the whole script? This error is saying that you tried to use the sub function.

surely no

Are you sure that the error you showed is portained to this script? Because the error has nothing to do with what’s in that script.

1 Like

I got distracted, after using tonumber() the error changed, and went to “compare boolean and number”, I had forgot to change boolvalue to numbervalue

1 Like