Click play to end cutscene and spawn in

I already have it so when you join the game the title is on the screen and same with the play button. Before you click play there is a camera moving around the map. I also have it so when you click play it removes the gui and should switch to the players camera view. But when it switched you spawn as an invisible person who cant move. How would I fix this? Here is what I have.

Starting GUI:

Workspace StarterGUI:
image

Script under ServerScriptService:

local Players = game:GetService("Players")
local Event = ReplicatedStorage:FindFirstChild("spawnPlayer")
local PlayersFolder = ReplicatedStorage:FindFirstChild("PlayersFolder")
if not Event then
	local newEvent = Instance.new("RemoteEvent")
	newEvent.Name = "spawnPlayer"
	newEvent.Parent = ReplicatedStorage
	Event = newEvent
end
if not PlayersFolder then
	PlayersFolder = Instance.new("Folder")
	PlayersFolder.Name = "PlayersFolder"
	PlayersFolder.Parent = ReplicatedStorage
end

Event.OnServerEvent:Connect(function(Player)
	if Player:GetAttribute("loadedMenu") == false then
		Player:SetAttribute("loadedMenu", true)
		Player.Character.Archivable = true
		Player.Character.Parent = game.Workspace
		for i,v in pairs(game.Workspace:GetDescendants()) do
			if v:IsA("SpawnLocation") then
				Player.Character:MoveTo(v.Position)
				break
			end
		end
	end
end)

Players.PlayerAdded:Connect(function(Player) 
	Player:SetAttribute("loadedMenu", false)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	Character.Archivable = true
	for i,v in pairs(game.Workspace:GetDescendants()) do
		if v:IsA("SpawnLocation") then
			Character:MoveTo(v.Position)
			break
		end
	end
	task.wait()
	Character.Parent = PlayersFolder
	Player.CharacterAdded:Connect(function(Char)
		Char.Archivable = true
		if Player:GetAttribute("loadedMenu") == false then
			for i,v in pairs(game.Workspace:GetDescendants()) do
				if v:IsA("SpawnLocation") then
					Char:MoveTo(v.Position)
					break
				end
			end
			task.wait()
			Char.Parent = PlayersFolder
		end
	end)
end)

Localscript under the PlayButton:

local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camera = game.Workspace.Camera

StarterGui:SetCore("ResetButtonCallback", false)

local setting = {}
setting.cutsceneTime = 2;
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
local spawnCharacterEvent = nil

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 spawnCharacterEventFind = ReplicatedStorage:FindFirstChild("spawnPlayer")
	if spawnCharacterEventFind then
		spawnCharacterEventFind.Parent = nil
		spawnCharacterEventFind:FireServer()
		spawnCharacterEvent = spawnCharacterEventFind
	else
		if spawnCharacterEvent then
			spawnCharacterEvent:FireServer()
		end
	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(2)

local spawnCharacterEventFind = ReplicatedStorage:FindFirstChild("spawnPlayer")
if spawnCharacterEventFind then
	spawnCharacterEventFind.Parent = nil
	spawnCharacterEvent = spawnCharacterEventFind
end

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
			if MenuFrame ~= nil then
				MenuFrame.Visible = false
			else
				MenuFrame = GUI
				GUI.Enabled = false
			end
			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)

Video of the problem:
robloxapp-20220511-1752374.wmv (2.9 MB)

It seems like the spawnPlr() function request your character to be loaded or ‘respawned’.

The server handles the request but never ‘respawns’ the player.

Try using Player:LoadCharacter() on the server to resolve the issue.

Which script are you referring to?

The one under ServerScriptService

1 Like

Which line? Sorry I can’t find it under the script.

Line 20, try adding Player:LoadCharacter() under Line 20.

1 Like

I dont see spawnPlr().
image

spawnPlr() is a function in the Button’s LocalScript (at line 26), which sends a request to the server to load your the player’s character.

Which is why you should add Player:LoadCharacter() in the ServerScriptService Script to load the character.

1 Like

But where would I add it? Would anywhere work in the serverscriptservice?

You can add it after Line 20 in the ServerScriptService Script, should be perfect then.

Alr let me test this real fast.

I still did not spawn on the map.

image

Try removing Player.Character.Parent = game.Workspace (at line 22)

1 Like

That did not change anything yet. Still not spawning.

Someone mentioned that players can’t actually “not spawn before clicking play” but that have to spawn in a box 99999999999999999+ studs away and they can’t hear themselves move/jump. Then when they click play they teleport to the spawn locations. Is this easier?

Can you try adding a print("Hello World!") in the function (after Line 22 inside of the ServerScript)? It seems like the RemoteEvent is not even firing.

You could just put the player in a box under the map and give him 0 WalkSpeed & JumpPower to silence him.

If I give them 0 walkspeed and jump power they wont move when they spawn.