TweenService Help

Yeah the beauty is in the simplicity of the service. You don’t need to cancel a tween to start a new tween because the current tween on a part’s specific property will stop if another tween is played on top of it.
And then lets say you want to fade the part out as soon as it is done. Let me introduce you events.
If you look here

image

You can see in the picture the Create method returns a tween and the tween has an event called Completed that plays when the tween is finished or cancelled.

1 Like

Hey, thank you for all your help1 and you to o @LeeBurnor!

1 Like

You can actually use this event to tie together multiple tweens.

tween1.Completed:Connect(function()
 tween2:Play()
end)
1 Like

This is the best practice for tweens that I can think of.
Doing it this way will help with timing and reliability.

local function fire_projectile(projectile)
	local part = projectile:Clone()
	local total_time = 0

	local tween1 = TweenService:Create(
		part,
		TweenInfo.new(
			1,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.Out,
			0,
			false,
			0
		),
		{
			CFrame = part.CFrame + Vector3.new(80,0,0)
		}
	)
	total_time += tween1.TweenInfo.Time + tween1.TweenInfo.DelayTime
	local tween2 = TweenService:Create(
		part,
		TweenInfo.new(
			0.5,
			Enum.EasingStyle.Cubic,
			Enum.EasingDirection.Out,
			0,
			false,
			total_time
		),
		{
			Transparency = 1,
		}
	)
	total_time += tween2.TweenInfo.Time + tween2.TweenInfo.DelayTime
	
	Debris:AddItem(part, total_time)
	
	part.Parent = workspace
	
	tween1:Play()
	tween2:Play()
	
	return part
end

The idea with this code is to be able to time every animation without yielding the thread or missing an animation due to the animation being changed or interrupted. I know a lot of newer devs struggle with how to delete parts later and such. This will also finish the animation if the thread is canceled since the service is handling all the delays and animation.

The test place:
tween service example.rbxl (55.5 KB)

1 Like

hi! so tweening is just a way to smoothly change a value. for example if you want to tween 0 to 1 with the linear easing style, it will look something like 0, 0.01, 0.02, 0.03, 0.04, 0.05, etc. tweeninfo is just a way to specify how you want to tween it. the first parameter is the time in seconds in which the tween should complete. for example if i made it 2 for my previous example, it would go from 0-1 in exactly 2 seconds. then we have easing styles and easing direction. easing style is essentially how it reaches the goal. ex. exponential will start slow then get really fast! linear would just have the same speed. easing directions basically are used to reverse the easing style. ex. if you have easing direction out for exponential, it will start very fast then slow down. here is a post to help Understanding Easing Styles! - Resources / Community Tutorials - Developer Forum | Roblox. this is the easing direction documentation EasingDirection | Documentation - Roblox Creator Hub. and this is the tween info docs Tween | Documentation - Roblox Creator Hub. they each have examples and descriptions for further understanding. hope this helps

2 Likes