Why is ContextActionService:UnbindAction() not working?

I have a script that is supposed to create an action then after one section, unbind the action that was created. The action is created, but it is not being unbound. Does anybody know what the problem is?

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")
1 Like

Check the capitilization and spelling

Your script is getting hung up on ContextActionService:GetButton("DashButton"). A print statement before and after that line confirm it. The reason being, you’re not on mobile so the button doesn’t exist thus yielding your script. If you go into the emulator and select a mobile device you will see it being unbound.

2 Likes

Nevermind didn’t realise it was spelled correctly

On the wiki it states that if the button doesn’t exist the function should return nil. However, it seems it just never returns. I found this thread discussing the topic and their solutions.