I'm trying to add numbers to a NumberValue for my gameshow but it won't work. Can someone check my code?
local Value = workspace.Blue.Sign.Value.Value script.Parent.ClickDetector.MouseClick:Connect( function() Value + 100 end)
You cannot make pointers to attributes in Lua. Your code is actually storing the state of
Value at runtime, rather than making a reference to the property, "Value".
You also only performed an addition operation on
Value, which would have evaluated to
n + 100 on that line. You need to actually reassign
Value as the addition result:
Value = (Value + 100)
I highly recommend you do not name an Instance after an attribute affiliated to it, E.g
Value.Value. I'd rename it to
NumberValue, or give it a name that gives context to its purpose.
If you wish to change the property, you'll have to manually index it every time:
local NumberValue = workspace.Blue.Sign.Value script.Parent.ClickDetector.MouseClick:Connect(function() NumberValue.Value += 100 --// LuaU supports shorthand operands. end)