Cutscene Script

I have a script on the client that triggers a cutscene, I need the cutscene to trigger after a TextButton is clicked. How can I do this?


local camera = game.Workspace.Camera

function tween (part1,part2,cutsceneTime)
	
	local tweenInfo = TweenInfo.new(
		cutsceneTime,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	
	camera.CameraType =  Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame
	
	local tween = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
	tween:Play()
	
	wait(cutsceneTime)
	
	camera.CameraType = Enum.CameraType.Custom
end



wait(2)


tween(game.Workspace.Test1,game.Workspace.Test2,5)
tween(game.Workspace.Test2,game.Workspace.Test3,2)
tween(game.Workspace.Test3,game.Workspace.Test4,2)```

Very simple. Connect the button.MouseButton1Click event to your tween() function.

Code example:

local button = -- Your TextButton
button.MouseButton1Click:Connect(function()
    tween(part1, part2, cutsceneTime)
end)

If this works for you, please list this as the solution so others can easily find it as well. Thanks!

1 Like

okay wait, would this script go in the cutscene script? or the button?

Where is your cutscene script? I assumed it was parented to the TextButton.
If not, move your cutscene script so it’s parent is the TextButton. Here is the finished script:

local camera = game.Workspace.Camera
camera.CameraType = Enum.CameraType.Scriptable
local button = script.Parent

function tween(part1,part2,cutsceneTime)
	local tweenInfo = TweenInfo.new(
		cutsceneTime,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	
	camera.CameraType =  Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame
	local tween = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
	tween:Play()
	wait(cutsceneTime)
end

button.MouseButton1Click:Connect(function()
    tween(part1, part2, cutsceneTime)
end)

Please excuse if there are some syntax errors, I am not in Studio at this time.

1 Like

Thank you THANK YOU THANK YOU!!!

Why MouseButton1Click? Activated works as well, and I think allows for more platforms to use the button. I might be wrong, though.

I use MouseButton1Click in all my scripts. It works on all platforms.