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

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

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

✓ Accepted answer

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

2 comments

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.

0

alright

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