PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

UnbindAction

UnbindAction will unbind an action by name from user inputs so that the action handler function will no longer be called. Call this function when the context for some action is no longer applicable, such as closing a user interface, exiting a car or Tool/Unequipped|unequipping a Tool. See ContextActionService/BindAction|BindAction for more information on how bound actions operate.

This function will not throw an error if there is no such action bound with the given string. Using ContextActionService/GetAllBoundActionInfo|GetAllBoundActionInfo or the Developer Console’s “Action Bindings” tab, you can find out what actions are presently bound.

Parameters

Name Type Default Description

Returns

Return Type Summary

Code Samples


ContextActionService Tool Reload

This example properly shows how to use ContextActionService in binding user input to a contextual action. The context is the tool being equipped; the action is reloading some weapon. Test this code sample by placing it in a LocalScript parented to a Tool. When the Tool is equipped, a “Reload” action is bound, and when the Tool is unequipped the “Reload” action is unbound. When the player presses R with the Tool equipped, the message “Reloading!” will appear.

local ContextActionService = game:GetService("ContextActionService")

local ACTION_RELOAD = "Reload"

local tool = script.Parent

local function handleAction(actionName, inputState, inputObject)
	if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
		print("Reloading!")
	end
end

tool.Equipped:Connect(function ()
	ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)

tool.Unequipped:Connect(function ()
	ContextActionService:UnbindAction(ACTION_RELOAD)
end)