I'm trying to create gun logic for my game, the reloading works fine with the old depreciated keyboardInput method, but I don't really want to use something that's depreciated so I decided to try using the new method, and it's still firing after the tool has been put away, here's an example of what I have.
[StarterPack] [Tool] [LocalScript] [Handle]
Inside the tool is a simple localScript
local tool = script.Parent
tool.Equipped:connect(function(mouse)
local function reloadKey(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then
print(tool.Name)
end
end
game.ContextActionService:BindAction("keyPress", reloadKey, false, Enum.KeyCode.R)
end)
If you equip the tool then un-equip it and press 'R' it will still call the reloadKey function, if you equip the tool and un-equip it 10 times, it will print the tool name 10 times. I'm trying to figure out a way to only have this run when the tool is equipped.

2 comments
Incase anyone else runs into this and needs help with it, every time ContextActionService:BindAction() is called, you have to unbind it when you don't want it to listen anymore using ContextActionService:UnbindAction(). Where I went wrong in my post was, every time I equipped the tool it would create a new instance of the ContextActionService keyPress"
ContextActionService is a Service, so you need to use the :GetService() yeilding function for example game:GetService("ContextActionService")