Help with contextActionService

I wanted to make a button for mobile players that can import the keybind “T”, if they clicked it the block would fall from their arms but how? (Video example)

As I made this one for pc users
image
I was also trying to import the keybind “T” use contextActionService.
But what stuff do I need to change when using -contextAction- for mobile players so the script can work as it does for pc players?

Any help is appreciated, thanks.

I can’t give you any specific code but I can give you code from the wiki:

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)

If you check the wiki, there’s a section on adding mobile buttons, you would need to follow that!

Source: ContextActionService | Documentation - Roblox Creator Hub

1 Like

Would look into it now, thanks!

2 Likes