ContextActionService is broken

Was working on a slide mechanic when I came across this.

Buttons made with ContextActionService do not change position for me. I did some research, and it happened to others years ago. No errors happened, and I read the documentation.

Code:

local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")

local slideCooldown = false

local function slide()
	if slideCooldown then return end
	
	slideCooldown = true
	
	print("Slide")
	
	task.wait(3)
	slideCooldown = false
end

UserInputService.InputBegan:Connect(function(input, gameProccessedEvent)
	if gameProccessedEvent then return end
	
	if input.KeyCode == Enum.KeyCode.C or input.KeyCode == Enum.KeyCode.ButtonL2 then
		slide()
	end
end)

ContextActionService:BindAction("Slide", slide, true)
ContextActionService:SetTitle("Slide", "Slide")
ContextActionService:SetPosition("Slide", UDim2.new(0, 0, 0, 0))
1 Like

Hi, I tested your script and I had the same problem. :SetPosition is not working for some reason. I also tried to get the ImageButton using :GetButton method, but that didn’t work it’s just yielding infinitly, maybe this is a bug with ContextActionService. The best solution I could find is creating another method to obtain the slide button from PlayerGui by it’s Title, then set the Position manually.
Here is the script:

local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")
local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui")

local slideCooldown = false

function getButtonByTitle(buttonTitle:string)
	local ContextButtonFrame = PlayerGui:WaitForChild("ContextActionGui"):WaitForChild("ContextButtonFrame")
	for i,v in ContextButtonFrame:GetChildren() do
		if v.ActionTitle and v.ActionTitle.Text == buttonTitle then
			return v
		end
	end
end

function slide()
	if slideCooldown then return end

	slideCooldown = true

	print("Slide")

	task.wait(3)
	slideCooldown = false
end

UserInputService.InputBegan:Connect(function(input, gameProccessedEvent)
	if gameProccessedEvent then return end

	if input.KeyCode == Enum.KeyCode.C or input.KeyCode == Enum.KeyCode.ButtonL2 then
		slide()
	end
end)
ContextActionService:BindAction("Slide", slide, true)
ContextActionService:SetTitle("Slide", "Slide")

--Even GetButton is not working
--local slideButton = ContextActionService:GetButton("Slide")
--slideButton.Position = UDim2.new(0.93, 0,0.589, 0)

local slideButton = getButtonByTitle("Slide")
slideButton.Position = UDim2.new(0, 0,0, 0)

If you don’t like this solution, you can just create the buttons by yourself using ImageButton and so on, its really not hard and more customizable.