Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to detect touch screen controls?

I'm trying to detect the movement keys (W,A,S,D) on touch screen but can't figure out how.

What I have so far:

UIS.TouchStarted:Connect(function(touch, gameProcess)
	if touch.UserInputType == Enum.UserInputType.Touch then 
		
	end
end)

1 answer

This code has not been tested so I am not sure if it will work. The UserInputService is used to detect if the user input type is a mobile device, if it is it will proceed to the rest of the script, if it is not, it will not proceed but you can change it to what you want it to do:

local uis = game:GetService("UserInputService")

if uis.KeyboardEnabled == false and uis.TouchEnabled == true then
	
	print("Touch screen is enabled")
	
	
	function OnTouch(input,gameProcessedEvent)
		
		if input.UserInputType == Enum.UserInputType.Touch then
			
			--- Code Here
			
		end
		
	end
	uis.InputBegan:Connect(OnTouch)
	
	
else
	print("Touch screen is not enabled")
	
end

2 comments

0

doesn't have any code to detect the player's movement. I'm trying to detect if they are moving forward, backward, left, right

0

In that case you can use the ContextAction service, to understand it better there is a video link here: https://www.youtube.com/watch?v=1ZDnqtL4nX0, there is also a post showing all the things you can do with this service: https://www.robloxdev.com/api-reference/class/ContextActionService . The code above is base code on how to detect that it is a mobile device.

This discussion is preserved as it was. New answers, comments, and votes are closed.