Using TweenService to rotate GUI obj and it's not working

Here is my script:

while true do
	local TweenService = game:GetService("TweenService")
	local Object = script.Parent
	
	local tweenInfo = TweenInfo.new(
		2,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.Out,
		1,
		false,
		0
	)
	
	local Tween = TweenService:Create(Object, tweenInfo, {Rotation = 360})
	Tween:Play()
	wait(2)
	Object.Rotation = 0
	wait(math.random(30,120))
end

The button just sits there and does nothing. No errors. All help is appreciated.

2 Likes

So Gui’s default rotation is 0°, rotating it 360° means it’ll just be in the same position, there’s nothing to change in rotation so it just stays there. Sorry if I couldn’t explain correctly, basically what you are doing is tweening 0° to 0°.

2 Likes

Try changine Rotation to 359 and add 1 afterwards?

1 Like

Try to change the rotation from 360 to 359.

Also, an easier way is

local Object = script.Parent

while true do
    wait(0.005) -- you can change how fast/slow it rotates
    Object.Rotation = Object.Rotation + 1
end

This is the simplest way. Try these 2 and hopefully it’ll work.

I know this is late, but the person is trying to use tweening.

Make sure the element you’re trying to rotate is not restricted by something like a sibling UIListLayout or any other element that affects its siblings.

I suggest placing the element you’re trying to rotate inside an identical one and rotate the child-element.

Like so:
image
(apply the tween to the child of icon, highlighted in blue)

Your code seems okay, I did not test it so I cannot confirm, but from what I can see it should loop fine.

:slight_smile:

Edit:
I created my own variant of the infinite spin, your code could be made a lot more effective like this:

local spinIcon = script.Parent
local spinInfo = TweenInfo.new(1, Enum.EasingStyle.Circular,
Enum.EasingDirection.InOut, -1, false, 0)

local spin = tween:Create(spinIcon, spinInfo, 
{Rotation = spinIcon.Rotation + 360})

spin:Play()