Problems when pressing a key twice

Hello, I would like to know how to do so that when pressing ‘n’ for the first time the first print “activated” appears and if I press n again the second print “deactivated” appears.

local input = game:GetService("UserInputService")

input.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.N then
		print("activated")
		if inp.KeyCode == Enum.KeyCode.N then
			print("deactivated")
		end
	end
end)

Does anyone know how to do that?

We need some sort of variable to track if the current situation IS activated.

Something like this will do:

local input = game:GetService("UserInputService")

local isActivated = false --the variable that will determine if it is activated or not

input.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.N then
        isActivated = not isActivated
		if (isActivated) then
            print("activated")
       else
            print("not activated")
        end
	end
end)
2 Likes