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

wait() does not wait and runs next code instantly?

Asked by 2 years ago

I want to make a door that opens after 5 seconds. I used wait() but instead of waiting, it tweens the door instantly.

Script:

local TweenService = game:GetService("TweenService")
local tweenPart = script.Parent.Door1
local tweenPart2 = script.Parent.Door2

local info = TweenInfo.new(
    script.Parent.Open.TimeLength,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.InOut,
    0,
    false,
    0
)

local goals = {
    Position = script.Parent.Door1Open.Position
}

local goals2 = {
    Position = script.Parent.Door2Open.Position
}

local tween = TweenService:Create(tweenPart, info, goals)
local tween2 = TweenService:Create(tweenPart2, info, goals2)

wait(5)

tween:Play()
tween2:Play()

Any help please?

1 answer

Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
2 years ago

The tween you played does not wait for you, so you have to wait for it.

In a nutshell, playing a tween doesn't make it continue the rest of the code after the entire tween have played


tween:Play()

wait(script.Parent.Open.TimeLength) -- This is the same amount of time as the TweenInfo

tween2:Play()
0
both tweens played at once, but maybe the problem was the code starts running when the game starts, before the loading screen. I increased wait to 20 but at tweeninfo, the timelength of the open sound is 0, means the door is instantly opened without tweening it. GamerLighting23233 63 — 2y
0
alright Xapelize 2658 — 2y
Ad

Answer this question