How should I be scripting my game if I want to include both desktop + mobile?

Like, for example. If I have a mouse over event. Then that wont work with mobile. Is there a way to detect if a user is mobile or desktop?

And I could have certain functions run if either is detected? Or how do you go about dealing with this?

IIRC (If I remember correctly), you can create an if statement in case a Roblox player is in either Desktop/Mobile while getting the UserInputService. Example:

local In_Mobile = game:GetService(”UserInputService”).GamepadEnabled
local In_Desktop = game:GetService(”UserInputService”).KeyboardEnabled

local Players = game:GetService(”Players”)

    if In_Mobile then
        print(player.Name, “is in Mobile”)

    if In_Desktop then
        print(player.Name, “is in Desktop”)

Does the In_Mobile and In_Desktop automatically take the local player? Or how does it know which player?

It should be TouchEnabled.

It runs in a LocalScript as UserInputService is a local service.


1 more question, is this normal for ppl who wanna make mobile/desktop game? To make different functionality for either?

1 Like

Yep. Just like in any other engine. Though, some experiences, like phantom forces, have separate experiences for different devices so it’s easier to manage.

1 Like

Sometimes there’s API that allows you to do both and not have to detect which device the user is currently using. For example, ContextActionService allows the developer to create a touch button which will be present if the client has touch.

Functionality should always be available for all devices unless it is truly incompatible with that device.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.