✓ Accepted answer
The problem is with your function. You have no connection line, and you're not calling it. Also, you can't access the NumberValue's value directly like that.
local value = game.Players.NumberValue
print(value)
Having the value set as this stores the value as a number. Not the object itself.
This would print whatever the NumberValue's Value is, not the NumberValue.
For example, if the NumberValue's Value was set at 5, this would print out "5" instead of "NumberValue".
For your script to work, we need it to be set as the object, which is "NumberValue".
To fix this, try the script below:
local value = game.Players.NumberValue
function add()
value.Value = 0
value.Value = value.Value + player.Character.Torso:GetMass()
end
add()
Anyways, this should work now. If you have any problems or questions, please leave a comment below. Hope I helped :P
5 comments
dyler, I think line 08 should be add() not function().
Yeah. Also, if you wanted to connect it to a touched event for example, you'd do something like part.Touched:connect(add) at the bottom of the script instead of add(), where part is the path to the part that's going to be touched.
Great answer! Thank you so much, the help is very appreciated.
I was aware of how to use a function beforehand, btw. The function I presented was just an example. Just assume it's called later in the script. I get the gist of it now, though. I should be setting the variable to the object and not the value. Thanks again.
No prob. Glad I could help, and thanks for pointing that out ContinentofEurope, I fixed it.