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

Having trouble adding two number values together?

Asked by 3 years ago

Im making a simple tycoon and for the droplets that fall from the dropper, they have a numberValue of 1. The collector also has a numberValue, when the droplets fall on the collector the collecotr's script is supposed to add the value of the droplet to itself but i keep getting an error

Code

script.Parent.Touched:Connect(function(hit)
    local coin = game.Workspace:WaitForChild("coin")
    if hit == coin then 
        script.Parent.Value += 1
    end
end)

error

Workspace.Collector.Script:4: attempt to perform arithmetic (add) on Instance and number

1 answer

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago
Edited 3 years ago

from what it seems, Value is a NumberValue. If that's the case you should do:

script.Parent.Value.Value

instead of

script.Parent.Value

your error probably occurred because Value (the numbervalue itself) is an instance and Value (the property) is a Number

0
basically you tried to add 1 to an instance (object), which you can't do NGC4637 602 — 3y
Ad

Answer this question