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)
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)
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
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
doesn't have any code to detect the player's movement. I'm trying to detect if they are moving forward, backward, left, right
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.