Imagine theres an Imagebutton in StarterGui, and when you hold that button on mobile, a function activates which fires bullets, and stops when you release the button.
That’s basically what i’m planning, and i know that you can easily achieve that by using UserInputService’s MouseButton1Down, but is there any way to script it using ContextActionService?
You could disconnect the action if the player is on mobile and instead fire a remote event that would do the same thing on the server (with userinputservice).
First, buttons that CAS create are just UIs and they can get modified.
What you can do here is just getting the button by GetButton Function with the name of the action as parameter, and modify it with the properties you want to.
That’s what I came up with as Roblox studio isn’t available right now. I don’t know if there is actually a straight-forward method to achieve what you want.
Hope my reply helped you!
EDIT 1
This reply is originally an answer for your question:
EDIT 2
In order to get the feature/ mechanic you want, you basically need the MouseButton1Down event from imageButton.
I am pretty sure you can do that. Simply in the action handler function check for if the action has started, or ended
local ContextActionService = game:GetService("ContextActionService")
local ACTION = "Reload"
local tool = script.Parent
local function handleAction(actionName, inputState, inputObject)
if actionName == ACTION and inputState == Enum.UserInputState.Begin then
print("Pressed")
elseif actionName == ACTION and inputState == Enum.UserInputState.End then
print("Released")
end
end
tool.Equipped:Connect(function ()
ContextActionService:BindAction(ACTION, handleAction, true, Enum.KeyCode.R)
end)
tool.Unequipped:Connect(function ()
ContextActionService:UnbindAction(ACTION)
end)