How to unbind a custom action?

Hello there!

I have recently started to learn about ContextActionService, and I have rebinded the space key so it makes a player dash. The problem is, I am making a cutscene with the player in it. The problem is that the player can still dash during the cutscene, making it shorter than it should be.

Is there a way to unbind a custom action using ContextActionService?

ContextActionService:UnbindAction()

ContextActionService:UnbindAction(name) is what you’re looking for. Just make sure you pass the name of the binded action.

So I typed this:

local mobileButton = ContextActionService:BindAction("DashButton", mobileDashPress, true, Enum.KeyCode.Space)

Would I pass mobileButton or DashButton?

You would pass DashButton, as that’s what you named it.

1 Like

Still not working, the player still dashes forward.

Here is the entire script:

if not game:IsLoaded() then game.Loaded:Wait() end
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:UnbindAction("jumpAction")
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local invincibility = false
local dashCooldown = false
character:WaitForChild("Humanoid").JumpPower = 0
function mobileDashPress()
		if dashCooldown == false then
			invincibility = true
			dashCooldown = true
			character.Humanoid.WalkSpeed = 75
			wait(0.4)
			character.Humanoid.WalkSpeed = 16
			wait(0.25)
			dashCooldown = false
			invincibility = false	
	end
end

local mobileButton = ContextActionService:BindAction("DashButton", mobileDashPress, true, Enum.KeyCode.Space)
local DashButton = ContextActionService:GetButton("DashButton")
ContextActionService:SetPosition("DashButton", UDim2.new(1, -95,1, -90))
ContextActionService:SetImage("DashButton","http://www.roblox.com/asset/?id=5853926901")
DashButton.Size = UDim2.new(0, 70,0, 70)

wait(1)

ContextActionService:UnbindAction("DashButton")
if not game:IsLoaded() then game.Loaded:Wait() end
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:UnbindAction("jumpAction")
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local invincibility = false
local dashCooldown = false
character:WaitForChild("Humanoid").JumpPower = 0

function mobileDashPress()
	if dashCooldown == false then
		invincibility = true
		dashCooldown = true
		character.Humanoid.WalkSpeed = 75
		wait(0.4)
		character.Humanoid.WalkSpeed = 16
		wait(0.25)
		dashCooldown = false
		invincibility = false	
	end
end

ContextActionService:BindAction("DashButton", mobileDashPress, true, Enum.KeyCode.Space)
local DashButton = ContextActionService:GetButton("DashButton")
ContextActionService:SetPosition("DashButton", UDim2.new(1, -95,1, -90))
ContextActionService:SetImage("DashButton","http://www.roblox.com/asset/?id=5853926901")
DashButton.Size = UDim2.new(0, 70,0, 70)

task.wait(1)

ContextActionService:UnbindAction("DashButton")

Its still not working, I think the local only means that it can’t be used outside of the script.