Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i play a different tween after one finishes?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!)

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. Realbluedrago 8 — 4y
0
script: Spin1:Play() Spin1.Completed:Connect(function() print("Tween ended!") Spin2:Play() end) Realbluedrago 8 — 4y
0
add a wait. Nicholas1088 169 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

idk how

0
Don't post this if you don't know how. Nicholas1088 169 — 4y

Answer this question