I’m trying to have this GUI rotate when the red button is held. It rotates but only to 20-96 and I’m very confused.
anchorpoint.MouseButton1Down:Connect(function()
Held = true
Runservice.Heartbeat:Connect(function()
if Held then
wait(0.05)
local degrees = math.deg(math.atan2(mouse.X - MapGui.CompassTemp.Position.X.Scale, mouse.Y - MapGui.CompassTemp.Position.Y.Scale))
if degrees > 180 then
degrees = -(360-degrees)
elseif degrees <-180 then
degrees = 360+degrees
end
mouse.Button1Up:Connect(function()
Held = false
end)
MapGui.CompassTemp.Rotation = degrees
end
end)
end)
You have put a Heartbeat loop inside a Button1Down signal, so every time the mouse button is clicked, it will then also create a heartbeat loop, the heartbeat loop isn’t being disconnected anywhere so one could assume you could have x amount of loops running at once.
If you wanted to make it constantly rotate in the same direction, you could just keep adding to the figure and it will continue turning.
I would do something like this, though without seeing all your code I have no idea if it would work.
local Held = false
RunService.Heartbeat:Connect(function(Delta)
if Held then
MapGui.CompassTemp.Rotation += 0.1
end
end)
anchorpoint.MouseButton1Down:Connect(function()
Held = true
end)
anchorpoint.MouseButton1Up:Connect(function()
Held = false
end)