It sounds like your function is being triggered on both the InputBegan and InputEnded events. To ensure the function only triggers once when the button is pressed, you should check the inputState parameter in the function, and only execute your code when inputState is Enum.UserInputState.Begin.
Here's how you can do it:
lua
CopyEdit
localContextActionService = game:GetService("ContextActionService") local function onButtonPress(actionName, inputState, inputObject) if inputState == Enum.UserInputState.Begin then print("Button Pressed!") -- Replace this with your desired action end end ContextActionService:BindAction("MyButtonAction", onButtonPress, true, Enum.UserInputType.Touch)
The onButtonPress function checks if inputState is Enum.UserInputState.Begin before executing any code.
ContextActionService:BindAction binds the function only to Enum.UserInputType.Touch, which is used for mobile devices.
This will ensure the function is only called once when the button is pressed, not when it's released.