Help With Mobile Interactions

So currently I have a tool that activates if you click/touch. However on mobile, the tool will activate if the player moves with the joystick, or if they move their finger on the screen to move around. What could be a possible solution?

2 Likes

You could move the tool’s code into a TextButton / ImageButton for mobile, and have .Activated on the button activate the tool.

1 Like

The tool requires you to aim, so I don’t think this would work very well.

Have you tried TouchTap? It fires when a tap happens, which seems like it would fit your use case, however you didn’t really give that much info so we can’t fully help you. If you need to press down, you might try TouchStarted and just do a simple check if it was processed by the engine with if gameProcessedEvent then return end.

Thanks to @ForgetableLife I found the answer, basically use just use Enum.SwipeDirection

Here is how I did it, copy that to a file in starterplayerscripts


local UIS = game:GetService('UserInputService')
local player = game.Players.LocalPlayer

function getCurrentTool()
	local chara = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
	return chara:FindFirstChildOfClass('Tool')
end

if UIS.TouchEnabled then
	UIS.TouchStarted:Connect(function(inp, processed)
		if processed then return end
		if table.find(Enum.SwipeDirection, inp.KeyCode) then return end

		local tool = getCurrentTool()
		if tool then tool:Activate() end
	end)

	UIS.TouchEnded:Connect(function(_, processed)
		local tool = getCurrentTool()
		if tool then tool:Deactivate() end
	end)
end
1 Like