Problem with ContextActionService button

When the player presses the sprinting button on mobile if they move their finger at all the sprinting will stop, I’ve attached a video of what’s happening emulated in studio, I’m holding the button down like you would normally but if the mouse moves at all the sprinting stops. This error doesn’t happen with the R key or ButtonL2. only the button for mobile

I tried looking around the dev hub but I didn’t find anyone with this issue. I’m confused

The script:

ContextActionService:BindAction("Sprint", function(name, state, input)
	if state == Enum.UserInputState.Begin then
		if ReplicatedStorage.CheckPlayerValues:FindFirstChild(Player.Name).StopRunning.Value == false then
			PlayAnim:Play()
			Sprinting = true
		end
	else
		PlayAnim:Stop()
		Sprinting = false
	end
	return Enum.ContextActionResult.Pass
end,true, Enum.KeyCode.R, Enum.KeyCode.ButtonL2)
ContextActionService:SetPosition("Sprint",UDim2.new(.25,0,0.6,0))
ContextActionService:GetButton("Sprint").Size = UDim2.new(0.35,0,0.35,0)
ContextActionService:SetImage("Sprint", SprintImage)

That’s because the else expression represents every input state that isn’t ‘Begin’, i.e; ‘Cancel’, ‘Change’ etc. You need to explicitly check that the input’s state is ‘End’.
elseif state == Enum.UserInputState.End then

4 Likes

This worked perfectly, thank you