-- place this script under the gui object you want to rotate and use the rotation and speed value to change the rotation (degrees) and speed (seconds for full loop)


local RunService = game:GetService("RunService")
function slerp(a,b,x)
	return a*(((1+(math.cos(x*math.pi)))/2)) + b*(((1-(math.cos(x*math.pi)))/2))
end

local object = script.Parent
local count = 0.0
local rotation = object.Rotation	

RunService.Heartbeat:Connect(function(step)
	count += step / script.speed.Value * 2
	if step <= 1 then
		object.Rotation = slerp(-script.rotation.Value,script.rotation.Value,count)+rotation
	else if step <= 2 then
			object.Rotation = slerp(script.rotation.Value,-script.rotation.Value,count)+rotation
		else
			count = 0
		end
	end
end)
