Click play to end cutscene and spawn in

I have the cutscene move from camera to camera. But I want it so when you click the play button the Title and play button disappear, the cutscene ends and the player spawns in. How would I do this?

I’ve made a new script which does everything you asked for.

  • Plays cutscene until player clicks play button
  • Once menu is invisible, spawns the character (uses LoadCharacter function to load the character)
ServerScript inside ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Event = ReplicatedStorage:FindFirstChild("spawnPlayer")
if not Event then
	local newEvent = Instance.new("RemoteEvent")
	newEvent.Name = "spawnPlayer"
	newEvent.Parent = ReplicatedStorage
	Event = newEvent
end

Event.OnServerEvent:Connect(function(Player)
	if Player:GetAttribute("loadedMenu") == false then
		Player:SetAttribute("loadedMenu", true)
		Player:LoadCharacter()
	end
end)

Players.PlayerAdded:Connect(function(Player) 
	Player:SetAttribute("loadedMenu", false)
	Player.CharacterAdded:Connect(function(Char)
		if Player:GetAttribute("loadedMenu") == false then
			Char:Destroy()
		end
	end)
end)
LocalScript inside your play button
local TweenService = game:GetService("TweenService")
local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camera = game.Workspace.Camera

StarterGui:SetCore("ResetButtonCallback", false)

local setting = {}
setting.cutsceneTime = 5;
setting.cutscenePrefix = "Test";
setting.tweenInfo = TweenInfo.new(
	setting.cutsceneTime,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
);
setting.TweenObjectsLocation = game.Workspace;
setting.myMethod = true; -- By using my method there will be a white flash tween which will tween a new frame to fully visible, change menu frame visible to false and then load to player

local inMenu = true
local menuVisible = true
local scenePlaying = false

function spawnPlr()
	menuVisible = false -- DO NOT DELETE THIS LINE! put it after the line where you change the menu frame visible to false
	StarterGui:SetCore("ResetButtonCallback", true) -- Keep this line with the line above it
	local spawnCharacterEvent = ReplicatedStorage:FindFirstChild("spawnPlayer")
	if spawnCharacterEvent then
		spawnCharacterEvent:FireServer()
	end
end

function tween(part1,part2)
	scenePlaying = true
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame

	local tween = TweenService:Create(camera, setting.tweenInfo, {CFrame = part2.CFrame})
	tween:Play()

	local finishFunc
	finishFunc = tween.Completed:Connect(function()
		scenePlaying = false
		finishFunc:Disconnect()
		finishFunc = nil
	end)
	repeat task.wait() until scenePlaying == false or inMenu == false
	if inMenu == false then
		repeat task.wait() until menuVisible == false
		camera.CameraType = Enum.CameraType.Custom
	end
end

task.wait()

local ObjectsToTween = {}
function addTweenObject(index, obj)
	ObjectsToTween[index] = obj
end

for i,v in pairs(setting.TweenObjectsLocation:GetChildren()) do
	if v.Name:lower():find(setting.cutscenePrefix:lower()) then
		if #v.Name > #(setting.cutscenePrefix) then
			local number = v.Name:sub(#(setting.cutscenePrefix) + 1, #v.Name)
			if tonumber(number) ~= nil then
				addTweenObject(tonumber(number), v)
			end
		end
	end
end

function StartTween()
	for i,v in pairs(ObjectsToTween) do
		if not inMenu then break end
		if i < #ObjectsToTween then
			tween(v, ObjectsToTween[i + 1])
		end
	end
end

coroutine.wrap(function()
	while inMenu do
		StartTween()
		task.wait()
	end
end)()

local function PlayButton()
	if not inMenu then return end
	inMenu = false
	if setting.myMethod then
		local GUI = script.Parent:FindFirstAncestorOfClass("ScreenGui")
		if GUI then
			local FlashFrame = Instance.new("Frame")
			FlashFrame.Name = "FlashFrame"
			FlashFrame.AnchorPoint = Vector2.new(0.5, 0.5)
			FlashFrame.Position = UDim2.new(0.5, 0, 0.5, 0)
			FlashFrame.Size = UDim2.new(1, 0, 1, 0)
			FlashFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
			FlashFrame.BorderSizePixel = 0
			FlashFrame.BackgroundTransparency = 1
			FlashFrame.ZIndex = 999999999
			FlashFrame.Parent = GUI
			local Visibility = true
			local Duration = 2
			local function createNewTween(visible)
				Visibility = visible
				local newTween = TweenService:Create(
					FlashFrame, 
					TweenInfo.new(
						Duration,
						Enum.EasingStyle.Sine,
						Enum.EasingDirection.Out
					),
					{
						BackgroundTransparency = Visibility == true and 0 or 1
					}
				)
				return newTween
			end
			local TweenObj = createNewTween(true)
			TweenObj:Play()
			TweenObj.Completed:Wait()
			TweenObj = createNewTween(false)

			local MenuFrame = nil -- Must specify
			MenuFrame.Visible = false
			spawnPlr()

			TweenObj:Play()
			TweenObj.Completed:Wait()
			FlashFrame:Destroy()
			-- You can put more of your code for additional stuff if you wish

		end
		return
	end
	-- If you don't want to use my method (you can set using my method to false in the settings table, if you want), just put your own code here which changes the menu visible and other things


	spawnPlr() -- DO NOT DELETE THIS LINE! put it after the line where you change the menu frame visible to false
end

script.Parent.MouseButton1Click:Connect(PlayButton)

A few things to keep note of:

  • You should see a settings table inside of the LocalScript. All the settings are there and you can change them if you want.
  • There is a “myMethod” setting and what this does is uses my method to make the title and play disappear (or menu), but you will have to specifiy what your menu frame is, in the MenuFrame variable, or your own variable (if you’re not using my method), or else it will not work!
  • I also suggest going through every line of the code and looking for the notes (notes look like this -- hello), I’ve created the notes so you know how to properly configure the script and understand it without making an error.

Also, whenever someone solves your topic, make sure to click the solution button to give them credit! There are others on here who might be having the same issue that you were having, so doing this would help them find the solution.

1 Like

@develofied I have tested this a couple times and it seems to be working!

I’ve also created a place if you want to go test it yourself.
Classic Baseplate.rbxl (33.9 KB)