Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could you make an image rotate back and forth smoothly?

I would like a way to rotate something back and forth very efficiently and smooth such as: https://gyazo.com/ce2763e854e1ab7ce923885591125d31

I can't seem to figure out how to do this (I'm sure I am over thinking this).

3 comments

0

you could use for loops (e.g, for i = 1,30 do) and change the rotation property (e.g gui.rotation = gui.rotation + 1)

0

Look into http://wiki.roblox.com/index.php?title=API:Class/TweenService/Create. This should allow you to tween almost any property.

0

Thats not tweening an image................

2 answers

✓ Accepted answer
--Things that you can change have been marked by *

local TweenService = game:GetService("TweenService") --Get Tween Service

local Gui = script.Parent --*The gui that we want to tween

local goal1 = {
	Rotation = 10 --*The Property Goal we want to change
}

local goal2 = {
	Rotation = -10 --*The reverse of Goal1
}

TweenTime = 2 --*The length of the tween

local tweenInfo = TweenInfo.new(TweenTime, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut) --Create a tweeninfo (TweenTime, Style, Direction)
 
local tween1 = TweenService:Create(Gui, tweenInfo, goal1) --Create the first tween (using properties goal1), (Instance, TweenInfo, Goal)
local tween2 = TweenService:Create(Gui, tweenInfo, goal2) --Create the second tween (using properties goal2)

spawn(function() --so code after this can run
	while true do --create a loop
		tween1:Play() --Play the first tween
		wait(TweenTime) --wait until the tween has finished
		tween2:Play() --do the second tween
		wait(TweenTime) --wait until second tween has finished
	end
end)

This should work if you put the local script inside of the guiobject or change the variable to where the gui is located

1 comment

0

it works very good and fine thx ;DD !!!

Use sine wave

part = script.Parent
x = 0
while wait() do
	y = 1*math.sin(x) -- change 1 to how high you want the sin wave to go on y axis
	part.CFrame = part.CFrame * CFrame.Angles(0,0,math.rad(y))
	x = x + 0.1
end

Just make sure script is inside the part, and i think this will work

2 comments

0

Did you watch the gif the guy provided?

0

Yeah, i didn't realise this was for a gui, I though it was far a part with a decal on it. However the same concept can still apply to the gui...

This discussion is preserved as it was. New answers, comments, and votes are closed.