Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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.

0
What's the object of the BuyAndSellAmount Cyrus_O4 45 — 3y
0
Just a tip, use the compounded operators +=, -=, *=, /=. x += y is the same as writing x = x + y. radiant_Light203 1166 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

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
0
wow i haven't thought of that Cyrus_O4 45 — 3y
0
Haha, you beat me to it. It's such a common problem with such a simple answer. Have an uprep. radiant_Light203 1166 — 3y
0
This can be shortened by doing: BuyAndSellAmount.Value -= numb A_thruZ 29 — 3y
0
This doesnt work at all, I tried it, same thing. usmaniusmangamer15 9 — 3y
View all comments (2 more)
0
Did you add .Value to ALL the BuyAndSellAmount. If you did are you sure that script.Parent is a Number/Integer value JustinWe12 723 — 3y
0
Nevermind. usmaniusmangamer15 9 — 3y
Ad

Answer this question