Changing Speed of Rotating Gui

Hello there!
I have an image label that rotates a certain speed, but how can I make the speed lower and raise every so often?
Here’s my script:

local Spin = script.Parent

while true do
	Spin.Rotation = Spin.Rotation + 1
	wait(0.0001)
end

I tried making a variable that is equal to true, then toggling that to false and true to change speeds, but it didn’t work. What can I do?

What I would do is after the wait statement, add Spin.Rotation = Spin.Rotation + 1 and substitute one for whatever speed you would like.

Tell me if that doesn’t work, I think it should.

What I’m trying to get is where it spins a few rotations, then slows for 1.5 seconds, then speeds back up, and repeats.

I’m not exactly sure what you want to do in the end, but a quick tip. Don’t use:

Instead use “wait()” if you don’t put anything between the wait it’ll be the minimum time for a wait


I’m trying to get the small spinning icon in the corner to speed up and slow down it’s spinning, like the real loading icon.

Maybe change Spin.Rotation = Spin.Rotation + 5 This will make it look like it’s rotating faster. Don’t put too big of a number, or the spin will look glitchy.

You can control the rate precisely by using an event-based method:

local Spin = script.Parent

local Frequency = 1 -- rotations / second
-- Frequency / 360 is degrees / second

game:GetService("RunService").RenderStepped:Connect(function(dt)
	Spin.Rotation = (Spin.Rotation + dt * Frequency / 360) % 360
end)

Since there’s no infinite loop it won’t lock up the script and you can change the ‘Frequency’ value any time you want.

1 Like

To make it slow down, you can use TweenSerivce(Tell me if you want more info on that) or you can modify your script:

local Spin = script.Parent

local StopCounter = 0

local SpinRotation = 1

local SlowDownSpeed = 0.1

while true do
	Spin.Rotation = Spin.Rotation + SpinRotation
if SpinRotation > 0 then
    SpinRotation = SpinRotation - SlowDownSpeed 
else 
    StopCounter = StopCounter + 1
    if StopCounter >= 10000 then
        StopCounter = 0
        SpinRotation = 1
    end
end
      
	wait(0.0001)
end

This script works, but when the rotation stops, it won’t speed back up, and it stays motionless. I’m not quite sure how to fix that.

local Spin = script.Parent

local StopCounter = 0

local SpinRotation = 6

local SlowDownSpeed = 0.1

while true do
	Spin.Rotation = Spin.Rotation + SpinRotation
	print(SpinRotation)
	if SpinRotation > 0 then
		SpinRotation = SpinRotation - SlowDownSpeed 
	else 
		SpinRotation = 0
		StopCounter = StopCounter + 1
		if StopCounter >= 30 then
			StopCounter = 0
			SpinRotation = 6
		end
	end

	wait()
end

It seems like the delay was too long. I made it shorter.