Tween forced to stop before continuing to next line of code

Hi,

I’ve got a script Tweening the camera to the correct postiion (if that makes sense) however:

When the script is running, it waits for 2 seconds on the following line:

wait (2)

tween(game.Workspace.Cam1,game.Workspace.Cam2)

This causes it to wait for 2 seconds before continuing to the next line (moving the camera further downwards)

If you have a look at the video below, you can see the problem.

I have attempted to move the wait (2) causing the problem, however this does not work and changes the position that the Camera starts from.

Any solutions?
The script is shown below.

local TweenService = game:GetService("TweenService")
local camera = game.Workspace.Camera
local cutsceneTime = 8
local cutscene2Time = 1.5
local tweenInfo = TweenInfo.new(
	cutsceneTime,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

function tween(Cam1,Cam2)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = Cam1.CFrame
	local tween = TweenService:Create(camera, tweenInfo, {CFrame = Cam2.CFrame})
	tween:Play()
	wait (cutsceneTime)
end

wait (2)

tween(game.Workspace.Cam1,game.Workspace.Cam2)

function tween2(Cam2,Cam3)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = Cam2.CFrame
	local tween2 = TweenService:Create(camera, tweenInfo, {CFrame = Cam3.CFrame})
	tween2:Play()
	wait (cutscene2Time)
	camera.CameraType = Enum.CameraType.Custom
end

wait (2)

tween2(game.Workspace.Cam2,game.Workspace.Cam3)
1 Like

Why do you have Tween() and Tween2()

What’s the difference?

The 1st and 2nd one are completely different, if you watch the video shown, you can see that the half transparent part is where 1 ends and 2 begins.

You should use the parameters in the Function so you say which part to tween too. This would be more efficient and would probably fix your problem. I’m happy to provide a script I have, Let me know :slight_smile:

THE PLAYSTATION SCREEN

Couldn’t you just detect until the first Tween finishes to play the next Tween?

local TweenService = game:GetService("TweenService")
local camera = game.Workspace.Camera
local cutsceneTime = 8
local cutscene2Time = 1.5
local tweenInfo = TweenInfo.new(
	cutsceneTime,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

function tween(Cam1,Cam2)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = Cam1.CFrame
    if Cam1 == game.Workspace.Cam2 then
        tweenInfo[1] = cutscene2Time
    end
	    local cooltween = TweenService:Create(camera, tweenInfo, {CFrame = Cam2.CFrame})
	    cooltween:Play()
	    cooltween.Completed:Wait()
    tween2(workspace.Cam2, workspace.Cam3)
end

function tween2(Cam1, Cam2)

end
wait(2)

tween(game.Workspace.Cam1,game.Workspace.Cam2)

I will give this a go and update you further.

Thank you, the following has worked.

local TweenService = game:GetService("TweenService")
local camera = game.Workspace.Camera
local cutsceneTime = 8
local cutscene2Time = 1.5
local tweenInfo = TweenInfo.new(
	cutsceneTime,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)
local tweenInfo1 = TweenInfo.new(
	cutscene2Time,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

function tween(Cam1,Cam2)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = Cam1.CFrame
	local tween = TweenService:Create(camera, tweenInfo, {CFrame = Cam2.CFrame})
	tween:Play()
	tween.Completed:Wait()
	tween2(workspace.Cam2, workspace.Cam3)
end


function tween2(Cam2,Cam3)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = Cam2.CFrame
	local tween2 = TweenService:Create(camera, tweenInfo1, {CFrame = Cam3.CFrame})
	tween2:Play()
	wait (cutscene2Time)
	camera.CameraType = Enum.CameraType.Custom
end

wait (2)

tween(game.Workspace.Cam1,game.Workspace.Cam2)
1 Like

Glad to know this worked for you. Have a good day :slight_smile:

If anyone wants to see the final version of this, you can find it here

(4) PS2 Startup Screen - Roblox