Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect touch screen controls?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
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 awesomeipod 607 — 6y
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. Nikkasfied 43 — 6y
Ad

Answer this question