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

Having trouble adding two number values together?

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

✓ Accepted answer

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

1 comment

0

basically you tried to add 1 to an instance (object), which you can't do

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