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

Make 2 rotations with the Tween Service?

Recently, I have been trying to make a crate system and for the opening of the crate, I need to make it so the crate goes from right to left with its rotation. If you need an example of the crate opening system I am trying to make, Pet Simulator is a good place to look if you can't understand where I am coming from here.

This is the script I have got and it works fine for the first part with going right.

local TweenService = game:GetService"TweenService"
local tween = TweenService:Create(
    script.Parent,
    TweenInfo.new(1),
    {
        Rotation = 20
    }  
)
tween:Play()

But then I need it to go to -20 after that and then repeat, which I'm guessing could be used with a

whilst true do

end

command. If possible, I'm also trying to make it make it speed up the rotation over time, so once it is activated, which I can make do with a mouse click function, it will start to shake with the script whilst getting faster and bigger until then hiding.

Thanks!

1 answer

A tween created from TweenService actually has a Completed event that plays when the tween is fully finished tweening. It is also know as a callback some might say.

You can use the first tween and wait for it like this:


local TweenService = game:GetService("TweenService")
local tween = TweenService:Create(
    script.Parent,
    TweenInfo.new(1),
    {
        Rotation = 20
    }  
)
tween.Completed:Connect(function()
	-- tween rotation of crate -20 degrees
end)

tween:Play() -- will fire Completed event

I hope this helps and if you have questions you can ask me.

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