I am trying to figure out how to change the ScreenInsets property of a screen GUI based on device screen rotation.
I am trying to make my GUI use “DeviceSafeInsets” as the ScreenInsets type only when the player flips their phone that has a notched display to where the notch is on the right side of the screen and have it use “None” ScreenInsets when the device is flipped to where the notch is on the left, to get the most space used for my sidebar GUI, but cannot figure out anything that works well.
I tried looking on the roblox documentation and tried something like this:
local UserInputService = game:GetService("UserInputService")
local screenGui = script.Parent
UserInputService.DeviceRotationChanged:Connect(function(rotation, cframe)
if cframe.RightVector.X < 0 then
screenGui.ScreenInsets = Enum.ScreenInsets.DeviceSafeInsets
else
screenGui.ScreenInsets = Enum.ScreenInsets.None
end
end)
This code has a lot of issues. When you join the game when your phone is rotated with notch to the right, the code works the wrong way, and when you join with notch to the left, it kinda works. The code isn’t very good because the slightest movement of the phone kinda makes the property flip back and forth a bit, and it gets annoying.