Hello, I am trying to make a steering wheel that shows on mobile players screens when their driving cars. I am wanting to make it so the player can turn the steering wheel in between the numbers -270 and 270 but, when the player gets to 270 it’ll automatically goes back to 0 I don’t want it to do anything if the player keeps going.

Here’s what I got so far:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Selected = false
local function getAngle(frameCenter)
return (math.atan2(Mouse.Y - frameCenter.Y, Mouse.X - frameCenter.X))
end
local function radToDeg(a)
return a * 270 / math.pi
end
local function GetRotation(frame)
local middleFrame = frame.AbsolutePosition + (frame.AbsoluteSize / 2)
local angle = getAngle(middleFrame)
local degrees = radToDeg(angle)
return math.clamp(degrees, -270, 270)
end

I would have preferred if you just pasted your code into a reply, but anyway…

The issue, now that I look at it more closely, is that rotation goes from -180 to 180, a full 360 degrees, it automatically snaps to -180 if the rotation is 185 for example.

So, the correct clamping values would actually be:

local RotationClamped = math.clamp(math.deg(Radian), -135, 135)

, because 270 divided by 2 is 135, and now it works fine.

(you would probably also want to introduce some maximum angle difference limit, because the snapping is quite obvious if you move your mouse the full circle)

--how much the wheel can turn at once
--anything higher than this and the wheel will not turn
local MAX_MOVE_PER_UPDATE = 15
local LastRotation
Mouse.Move:Connect(function()
if Selected == true then
local NewRotation = GetRotation(script.Parent.MainGui.SteeringWheel)
--math.abs converts a negative number to a positive number
--but does nothing to positive numbers
if not LastRotation or math.abs(NewRotation - LastRotation) <= MAX_MOVE_PER_UPDATE then
script.Parent.MainGui.SteeringWheel.Rotation = NewRotation
LastRotation = NewRotation
end
end
end)