i found this youtube tutorial about how to set up a main menu with the camera moved to a certain position. the code works, but for some reason, it only works sometimes. other times, the menu doesnt run, and the camera is on the player like normal. why is this happening and how do i fix it? it seems to be happening randomly
code:
--code mostly taken from: https://www.youtube.com/watch?v=ecyKTDFOl5g&ab_channel=DevFlare
--changes made by me
local CurrentCamera = workspace.CurrentCamera --get local players camera
local CameraPart = workspace:WaitForChild("menucamerapart") --get the camera part
local PlayButton = script.Parent.Frame.PlayButton --get the actual play button on the frame
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") --get local player's humanoid
local Frame = script.Parent.Frame --get main menu frame
local TPPart = workspace.tppad --location to tp player after clicking play
wait(0.001) --no clue why this is here tbh
CurrentCamera.CameraType = Enum.CameraType.Scriptable --allow camera to be controlled by scripts
CurrentCamera.CFrame = CameraPart.CFrame --set camera's cframe to the cframe of the camera part
Frame.Visible = true --make frame visible (just easy to work on studio with this, dont gotta hide ui n stuff)
Humanoid.WalkSpeed = 0 --player cant move when main menu is on
Humanoid.JumpPower = 0 --player cant jump when main menu is on
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
function Play()
CurrentCamera.CameraType = Enum.CameraType.Custom --set camera back to default settings
Humanoid.WalkSpeed = 24 --let player move
Humanoid.JumpPower = 50 --let player jump
Humanoid.Parent:MoveTo(TPPart.Position) --tp player on the map from spawn box
script.Parent:Destroy() --remove the main menu
end
PlayButton.MouseButton1Click:Connect(Play) --run it