Attempt to perform arithmetic (sub) on Boolean and number

Just included it in the script.

I can’t find it, I mean IDK what else to say other than to make sure val is a number and not a string.

Val is a number lol

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Assets = require(ReplicatedStorage.Databases.Assets)
local ValueBox = {}
ValueBox.__index = ValueBox
local bankValues = {Bank = 0, Cash = 0}
local bankFrame = ValueBox.new(Assets.IconRect.Bank)
local cashFrame = ValueBox.new(Assets.IconRect.Cash)

Before line 77, create a line that says

if typeof(val) == “number” then print(“is number”) end

Now check if it prints “is number”


Also since I’m on iOS my quotes are different characters than the normal quotes for some reason.

It printed out the “is number”

Are you still getting the same error?

Then it isn’t val, it’s the other one. Do the same but for the other variable.

If I remove:

if typeof(val) == "number" then 
				print("is number") 
			end

It’ll add back the error: attempt to perform arithmetic (sub) on Boolean and number

Place this before line 77 and see what’s outputted.

On line 77, change val to tonumber(val)

If no error, then it succeeded.
Is error is that it’s nil, then val was a boolean.

Why would I want to change val to tonumber(val) on line 77?

if:

else
			local diff = val - bankValues.Cash
			bankValues.Cash = val
			cashFrame:SetValue("$" .. ShortenNumber(bankValues.Cash), diff)
			cashFrame:SetExactValue("$" .. bankValues.Cash)
		end

Because you are performing an arithmetic operation?

It prints out the number of money/cash in my bank value and cash value in-game:

image
image

If I add in:

print(val)
print(bankVales.Bank)

It would get rid of the error, but if I remove that, it’ll bring back the error.

Do what roblox said and try the tonumber() thing. It might be passed in as a string which is why it isn’t working.

Ah okay, that worked. I’ve seen you converted string to number object.

Because LUA converts strings automatically to a number, however, it errored out, resulting in using the tonumber() function to convert it from a string to number.

Edit: NVM it didn’t work I think

Edit 2: Regard that, it worked.

1 Like

Did you just copy from new haven county?