I have a cutscene in the background and on the screen is the title and the play button. I want it so players won’t spawn until after they hit the play button. How would I do this? Here are my current scripts:
2 Likes
Dude? Edit and reformat this post otherwise no one will attempt to help. No clue what is happening
2 Likes
I did the ``` and it came out weird
1 Like
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.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)
I haven’t read the script, but just to make sure, have you disable CharacterAutoLoads in Players?
2 Likes
How would I be able to do that?
Localscript underneath the PlayButton GUI:
local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camera = game.Workspace.Camera
StarterGui:SetCore("ResetButtonCallback", false)
local setting = {}
setting.cutsceneTime = 12;
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)
1 Like
How do I disable CharacterAutoLoads?
1 Like
It’s located in “Players” properties as a checkbox.
2 Likes
Like everybody else said, you’ll have to disable Players.CharacterAutoLoads and manually load the player with Player:LoadCharacter. I strongly recommend checking the API reference page.
3 Likes
im late 1 year but, how do i make it that the gui still appear? it doesnt appear if u uncheck the box