Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you fix the error: fix attempt to preform arithmetic (add) on instance and number?

Hello! I've been experiencing this error with NumberValues and IntValues, I was wondering if anyone can help I guess.

local BuyAndSellAmount = script.Parent
local number = math.random(1,6)

while true do
	wait(5)
	if number == 1 then
		
		local numb = 1
		
		print("+1")
		BuyAndSellAmount = BuyAndSellAmount + numb

		
	elseif number == 2 then
		
		local numb = 0.1
		
		print("+0.1")
		BuyAndSellAmount = BuyAndSellAmount + numb

	elseif number == 3 then
		
		local numb = 2
		
		print("+2")
		BuyAndSellAmount = BuyAndSellAmount + numb

	elseif number == 4 then
		
		local numb = 1
		
		print("-1")
		BuyAndSellAmount = BuyAndSellAmount - numb

	elseif number == 5 then
		
		local numb = 0.1
		
		print("-0.1")
		BuyAndSellAmount = BuyAndSellAmount - numb

	elseif number == 6 then
		
		local numb = 2
		
		print("-2")
		BuyAndSellAmount = BuyAndSellAmount - numb

    


	end	

Also note that im currenently trying to add/subtract 2 numbers every few seconds.

2 comments

0

What's the object of the BuyAndSellAmount

0

Just a tip, use the compounded operators +=, -=, *=, /=. x += y is the same as writing x = x + y.

1 answer

This is because numb is a number while Buy and sell amount is not a number and is an instance. You should use .Value to get the value of the instance. for example

 BuyAndSellAmount.Value = BuyAndSellAmount.Value - numb

6 comments

0

wow i haven't thought of that

0

Haha, you beat me to it. It's such a common problem with such a simple answer. Have an uprep.

0

This can be shortened by doing: BuyAndSellAmount.Value -= numb

0

This doesnt work at all, I tried it, same thing.

0

Did you add .Value to ALL the BuyAndSellAmount. If you did are you sure that script.Parent is a Number/Integer value

0

Nevermind.

This discussion is preserved as it was. New answers, comments, and votes are closed.