How to lock ScreenOrientation as only Landscape in mobile devices?

I want my game to work only on Landscape when on mobile.
For that, I put this at the beginning of LocalScript:

game:GetService("StarterGui").ScreenOrientation = Enum.ScreenOrientation.LandscapeLeft

However, when I rotate my mobile, it’s entering in Portrait, ie, Landscape mode is not locked.

What can I do to prevent the game from switching to Portrait?

You’d probably need to keep setting the ScreenOrientation every heartbeat step

game:GetService("RunService").Heartbeat:Connect(function()
    game:GetService("StarterGui").ScreenOrientation = Enum.ScreenOrientation.LandscapeLeft
end)

Though I’m not sure if this would cause it to freak out if on portrait mode

2 Likes

This should not be the case, as the documentation clearly states that the device is locked in the chosen orientation and this is not happening:

1 Like

That’s the solution (tks @Abcreator):

In my case, I used game.Players.LocalPlayer.PlayerGui.ScreenOrientation = Enum.ScreenOrientation.LandscapeSensor because LandscapeSensor allows landscape in the two positions of the mobile.

3 Likes

I know this is a very late reply but I just wanted to let newcomers know that in StarterGui there is a property called ScreenOrientation. ScreenOrientation allows you to select from multiple types of screen orientations to set in your game.

Here are the current screen orientation types:

  • LandscapeLeft
  • LandscapeRight
  • LandscapeSensor
  • Portrait
  • Sensor

For more information, here is the documentation page: Mobile | Roblox Creator Documentation

28 Likes

Oh, indeed it is something much simpler!
I tested it and it actually works perfectly.
I will use this from now on.
Thank you very much!

1 Like

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