Variable is not changing

I want to increment the keyState variable, but it does not seem to change.

This is my code at the moment:

local keyState: number = 0

local function setControlCallback(key: string)
	local direction: number = (key == upKey) and 1 or -1
	self.callbackIds[key] = self.controlInput:SetCallback(
		function(event: string)
			if event == "InputBegan" then
				keyState = keyState + direction
			elseif event == "InputEnded" then
				keyState = keyState - direction
			print(keyState, direction)
			keyState = keyState + direction

The issue is that if keyState is 0 and direction is 1, my output will print

0 1

, eventhough I incremented keyState with direction. What I hoped to see is a succesful increment operation:

1 1

I have tried to use the += and -= operators, but that did not fix the issue (I still use them cause it saves some characters).

You should change line 1

local keyState = number
number.Value = 0

(oops i didnt read the whole thing lol)

I do not really understand your idea. Where does number.Value come from? keyState is not supposed to be a NumberValue.

event is not defined properly… This is just an oops moment… I cannot delete this topic, so I will solve it like this.