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

how do i play a different tween after one finishes?

i've been trying to research about this a lot, but i can't find an anwser. i want to make > Spin2 play after > Spin1 finishes, but the part just ends up freezing in place.

to clarify, the object is a cylinder inside the workspace.

here's my current code (sorry if it's weird, i'm new to coding):

TweenService = game:GetService("TweenService")
spininfo = TweenInfo.new(5,Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 2, false, 0)
spininfo2 = TweenInfo.new(3,Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 2, false, 0)
spininfo3 = TweenInfo.new(1.7,Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, false, 0)
local part = script.Parent


Spin1 = TweenService:Create(part,spininfo,{CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(180),0)})
Spin2 = TweenService:Create(part,spininfo2,{CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(180),0)})
Spin3 = TweenService:Create(part,spininfo3,{CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(180),0)})

Spin1:Play()

Spin1.Completed:Connect(function(playbackState)
	if playbackState == Enum.PlaybackState.Completed then
		Spin2:Play()
	end
end)

	
Spin2.Completed:Connect(function(playbackState)
	if playbackState == Enum.PlaybackState.Completed then
		Spin3:Play()
	end
end)

2 answers

✓ Accepted answer

You can do Tween.Completed, and it would indicate that the tween is completed! If you want more information click this link.

Use TweenService to be able to access the tween like such

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
 
local SLOW_DURATION = 10
 
local function slowCharacter(humanoid)
	local goal = {}
	goal.WalkSpeed = 0
 
	local tweenInfo = TweenInfo.new(SLOW_DURATION)	
 
	local tweenSpeed = TweenService:Create(humanoid, tweenInfo, goal)
 
	tweenSpeed:Play()
 
	return tweenSpeed
end
 
local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")
	local initialSpeed = humanoid.WalkSpeed
	local tweenSpeed = slowCharacter(humanoid)
	`tweenSpeed.Completed:Wait()`
	humanoid.WalkSpeed = initialSpeed
end
 
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end
 
Players.PlayerAdded:Connect(onPlayerAdded)

(Code from the DeveloperRoblox, check it out!)

3 comments

0

i got one problem tho. whenever the tween finishes, it doesn't start playing the other tween. i tried making it print something, then play Spin2. but it only printed, and didn't play.

0

script: Spin1:Play() Spin1.Completed:Connect(function() print("Tween ended!") Spin2:Play() end)

0

add a wait.

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