I’ve been working with ContextActionService using a tool. When the tool is equipped and the player presses “R” the output should print “Reloading!” like the documentation says… But it doesn’t for some reason! It’s the same script as it is in the documentation. I’ve tried all different places to put the LocalScript (in the tool itself, in the StarterPlayerScripts). But it doesn’t work. It simply doesn’t. The ContextActionService :BindAction
function only worked for me when I was putting it alone not inside an equip function or something. But when when I do the opposite my ContextActionService vanishes…
Here’s the script:
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "Reload"
local tool = game:GetService("StarterPack").Tool
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("Reloading!")
end
print("reached")
end
tool.Equipped:Connect(function()
ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)
tool.Unequipped:Connect(function()
ContextActionService:UnbindAction(ACTION_RELOAD)
end)
What could be the issue?