Text Label Rotation Loop Not Working

  1. What do you want to achieve? Keep it simple and clear!
    Want to make this kind of Animation:

  2. What is the issue? Include screenshots / videos if possible!
    I want my Text label to make a rotation loop, but it only goes one time and doesn’t do it again as you can see in the attached video:

  1. What solutions have you tried so far?
    I searched how to fix it on DevForum but I didn’t find anything. This my code:
local Title = script.Parent
local Rotation = Title.Rotation

for i = -10, 10 do
	Title.Rotation = i
	wait(0.1)
end
1 Like

Use tweens for this.
Try to experiment with the different easing styles until you get one that you like.

1 Like

You should use tweens!

The main thing to know about tweens is that there is a thing called easing styles & directions. A great site for this is https://easings.net/ - hover over the different graphs and see how the speed at which a property is adjusted changes over time. This can be useful to make different types of animations.

Here’s an example of how to use this:

-- Title is the variable which references the object you want to move. Make sure to set it.
local TS = game:GetService("TweenService");
local Time = 1;
local Info = TweenInfo.new(
    Time,
    Enum.EasingStyle.Sine, -- Uses sine wave easing style
    Enum.EasingDirection.InOut -- Smoothly start and stop rotating. Check listed site for details
);

while true do
    TS:Create(Title, Info, { Rotation = 10 }):Play();
    task.wait(Time);
    TS:Create(Title, Info, { Rotation = -10 }):Play();
    task.wait(Time);
end

You can learn more about tween service here: TweenService | Roblox Creator Documentation

Try messing with the easing style. See what happens if you change it to Circular, or Back. Good luck!

3 Likes

As everyone said, you should use tweens.

Your code does not work since it is in a for loop, but it is not wrapped in a while loop/repeat; which in your case, it will only start rotation from -10, and increment to 10.

You could although wrap this in a while loop, but it will snap to where it started; instead of rotating back to original position in an animation.

1 Like

@plasma_node @Pixelctrl @BriefYayyayyay Thank you guys for the support, It worked!!

1 Like

Imo the more optimized way to do instead of while true do is to check when tween completed and then play second tween. Like 1st tween rotates on 20 and 2nd tween rotates to -20 and you basically repeat it by tween.Completed:Connect(function()

I know this has already been marked as solved, but I wanted to throw out into the open this easier solution. You can easily produce a fluid looking rotation loop by using RunService.Hearbeat and math.sin combined with tick (you can use deltaTime provided by .Heartbeat, but tick is easier to understand).

local DEGREES_OF_ROTATION = 20
local SPEED = 2

local textLabel = script.Parent
game:GetService("RunService").Heartbeat:Connect(function()
	textLabel.Rotation = math.sin(tick()*SPEED) * DEGREES_OF_ROTATION
end)

Doing this will land you this result (ignore the choppy gif loop):

rotating-text-example

3 Likes
while true do
	local T1 = TS:Create(Title, Info, { Rotation = 10 });
	T1:Play();
	T1.Completed:Wait();
	local T2 = TS:Create(Title, Info, { Rotation = -10 });
	T2:Play();
	T2.Completed:Wait();
end

Would be better to let the engine indicate when the tweens have finished playing rather than arbitrarily yielding.

https://developer.roblox.com/en-us/api-reference/event/TweenBase/Completed

1 Like

Correct. Using task.wait(Time) is just something I wrote because its quick.

Technically you would need to write it as

while true do
	local T1 = TS:Create(Title, Info, { Rotation = 10 });
    T1:Play();
	T1.Completed:Wait();
	local T2 = TS:Create(Title, Info, { Rotation = -10 });
    T2:Play();
	T2.Completed:Wait();
end

Because you need the tween object and :Play() does not return that.

Seems my edit didn’t go through before, but yes the ‘TweenBase’ objects would need to be assigned to variables in order for the Wait instance method to be called through/on their Completed RBXScriptSignal objects.

After further inspection the proposed solution leaves a lot to be desired.

local TweenService = game:GetService("TweenService")
local Title = nil --Define 'Title' here.
Title.Rotation = -10
local Tween = TweenService:Create(Title, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {Rotation = 10})
Tween:Play()

Here we utilise TweenService:Create's ‘repeatCount’ and ‘reverses’ parameters in order to create a single ‘TweenBase’ object which loops indefinitely.

https://gyazo.com/b1382eb7a9e2dfb8a8f3fe19a9924489

1 Like

Well, I was aware that we could reverse and repeat tweens but I was not aware that you could have it run indefinitely.