How do I get device's orientation similar to a compass from UserInputService?

I want to get device’s orientation accurately.
I tried to use this script:

local Service = game:GetService('UserInputService')
if Service.GyroscopeEnabled then
		script.Parent.Background.Arrow.Rotation = acceleration.Position.Y
	game:GetService('Players').LocalPlayer:Kick('Your device does not support compass or you need to enable location or sensors on Roblox app permissions from device settings!')

It’s not getting the device’s orientation properly!
Is there a another script I can try?

Have you looked into DeviceRotationChanged? Is there a reason why it doesn’t work for you?

Yes I have also looked into DeviceRotationChanged, but in my scripts, I get the CFrame.Position.Y from the DeviceRotationChanged and it didn’t work.
I want to make a Gui that is similar to a compass.

CFrames contain rotation data as well. In your case it might be as simple as this.

local _, yRot, _ = CFrame:toEulerAnglesXYZ()

Ok, thanks for that I will try it later.

You could use the ScreenOrientation property of PlayerGui. If you want to know when the orientation changes then you can do PlayerGui:GetPropertyChangedSignal("ScreenOrientation"):Connect()

Hi, this is my first post! I finally got accepted!!!

Why would you not help?, all you did is say hi

local uis = game:GetService("UserInputService")

while wait(0.2) do
	if uis.GyroscopeEnabled then
		local np, deviceCFrame = uis:GetDeviceRotation()
		--now you have device orientation. Its a CFrame.


I meant like this:

The rotating degrees of a device! It’s a number.