How to make gui Rotating effect?

Hi Developers! I am trying to make gui rotating effect when mouseenter but it is doing too slow with wait(0.001) it needed to do too fast but it is doing too slow when i am changing wait(0.001) to 0.000000000000000001 nothing happening please help me if you can

script.Parent.MouseEnter:Connect(function()
for i = 1,45,2 do
wait(0.001)
script.Parent.Rotation = script.Parent.Rotation+1
end
end)

14 Likes

Increase the value of the rotation, this will increase the amount of degrees rotated each time the function is run.

3 Likes

Not really helping, but maybe you can use Tween.

2 Likes

Tween? there is no tweenrotation

2 Likes

Yes you can, Tween is base on the Value type not the Property.

3 Likes

TweenService created tweens change the property from the current, to the selected in the amount of time specified. You can make it rotate from 0 degrees to 45 degrees in 1/30th of a second, or in 30 seconds.
It all depends on what you specify.

You could also try using RunService and :BindToRenderStep() if you’re wanting it to go super fast (aka, each frame update, typically 60 fps, would make it rotate one degree)

1 Like

You should really be using TweenService for this as it is a much smoother way of rotating an object than the way you are trying to do it. TweenService gives you lots of control over how you want the tween to play, for example you can set how long you want the tween to take or how many times you want the tween to repeat.


First off we will need to define our variables. As TweenService is a service we need to get it through GetService() and it is better practice to put this at the top of your script with the other variables that will be used throughout your script:

local TweenService = game:GetService("TweenService")
local Object = script.Parent -- The object you want to tween.

Secondly we will need to create our TweenInfo. The TweenInfo is used as the settings of the tween. Like for example you can set how long you want the tween to take to complete and how many times you want the tween to run:

local tweenInfo = TweenInfo.new(
	5, -- The time the tween takes to complete
	Enum.EasingStyle.Linear, -- The tween style in this case it is Linear
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- How many times you want the tween to repeat. If you make it less than 0 it will repeat forever.
	false, -- Reverse?
	0 -- Delay
)

Next will need to create the tween. You can do this by simply doing TweenService:Create(). This takes 3 parameters, the first being the object that you want tweened, the second being the TweenInfo we created earlier and third being a dictionary of the properties you want tweened with the values you want them to be tween to:

local Tween = TweenService:Create(Object, tweenInfo, {Rotation = 360}) -- Creates the tween with the TweenInfo and what properties you want to change

Lastly before you test you need to tell the tween to play, this can be done by using Tween:Play(). Alternatively you can use Tween:Pause() to pause the tween and Tween:Cancel() to cancel the tween.

Full script:

local TweenService = game:GetService("TweenService")
local Object = script.Parent -- The object you want to tween.

local tweenInfo = TweenInfo.new(
	5, -- The time the tween takes to complete
	Enum.EasingStyle.Linear, -- The tween style.
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- How many times you want the tween to repeat. If you make it less than 0 it will repeat forever.
	false, -- Reverse?
	0 -- Delay
)

local Tween = TweenService:Create(Object, tweenInfo, {Rotation = 360}) -- Creates the tween with the TweenInfo and what properties you want to change
Tween:Play() -- Plays the tween

If you edit the code above you should be able to make it work for what you are trying to do.

References:

53 Likes
local TS = game:GetService("TweenService")

local Object = -- the object u are tweening
local TweenInfo = -- the basic tweeninfo
local Goal ={
     Rotation = -- the ending rotation you want
}

local Tween = TS:Create(Object, TweenInfo, Goal)
Tween:Play()

PS : What waterrunner said but in short xd

3 Likes

By the way, there is a minimum amount of seconds a wait function can wait. I think it’s 0.03 or something…

2 Likes

Try using this:
while true do
for i = 1,360,1 do
script.Parent.Parent.RotatingCircle.Rotation = i --RotatingCircle is your GuiObject
wait()
end
end

2 Likes

For loops are inefficient for moving items, since manipulating it while it is running will break the whole gui element. That’s why Tween Service is much more efficient.

1 Like

This was months ago now i can Do animating easy lol anyways thanks.

1 Like

Thank you @waterrunner I’ll be using this to make a daily spin reward wheel for players.

Works perfectly for rotating to whatever angle I randomize on the server so I know what the reward should be as it stops. Starts fast and then nicely slows down with easing out quad.

How do I properly detect when it has rotated, let’s say every 8th of a circle so I can do some clicking sounds, which would then get slower and slower as the wheel slows down?

This would work but a real programmer will roll eyes at it:

local connection90
local connection180

local function onRotationChanged90()
	if Object.Rotation >= 90 then
		print("rotation was 90") -- play sound here
		connection90:Disconnect()
	end
end

local function onRotationChanged180()
	if Object.Rotation >= 180 then
		print("rotation was 180") -- play sound here
		connection180:Disconnect()
	end
end 

connection90 = Object:GetPropertyChangedSignal("Rotation"):Connect(onRotationChanged90)
connection180 = Object:GetPropertyChangedSignal("Rotation"):Connect(onRotationChanged180)

How could I do this properly?
Please give some hints how I should try to solve this.

edit:
Would this work?
Tween a delay_number to be larger and larger with the same tweenInfo parameters and then use that in a loop to do the clicking sound at the same time the Gui is rotating.