How do I make a GUI element rotate towards my moue?

I am working on a cool loading screen for my game, and I want an element that will face my mouse position. I didn’t know how to do this, so I went on the dev forum. I was lucky enough to find an answer to this. It worked, but not as I intended. It wouldn’t really face my mouse, and mostly rotate to the right. It barely followed my mouse on the left side. The code doesn’t have any errors, and I couldn’t find a tutorial on YouTube. I have not been able to find a solution to this.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local RS = game:GetService("RunService")

while RS.RenderStepped:Wait() do
	local difference = (Vector2.new(mouse.X, mouse.Y) - script.Parent.AbsolutePosition)
	script.Parent.Rotation = math.deg(math.atan2(difference.X, difference.Y))
end

it’s expected to do that.
Change the sign and the script would look like this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local RS = game:GetService("RunService")

while RS.RenderStepped:Wait() do
	local difference = (Vector2.new(mouse.X, mouse.Y) - script.Parent.AbsolutePosition)
	script.Parent.Rotation = -math.deg(math.atan2(difference.X, difference.Y))
end
1 Like