I am making a Main Menu Gui for my game. I have set it so when you click play, a script teleports you to a different part. However, everything except the teleporting is working well but when I try to teleport, It says “char is not a valid member of player” in the output. Any ways around this?
Script:
local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait() --Gets the character of the player
local char = Player.Character
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera --The Main Menu camera
local PlayButton = script.Parent.GameInfo.PlayButton --The Play button in the Gui
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable --Camera manipulation
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame
Player.char.HumanoidRootPart.CFrame = workspace.Spawns.HumanSpawn.CFrame --Is supposed to set the players character position to the position of this part (This is the issue)
PlayButton.MouseButton1Click:Connect(function()
Camera.CameraType = Enum.CameraType.Custom
script.Parent.GameInfo.PlayButton.Visible = false --These are set invisible when play button is clicked
script.Parent.GameInfo.QuitButton.Visible = false
script.Parent.GameInfo.GameStuff.Visible = false
script.Parent.GameInfo.GameTip.Visible = false
script.Parent.GameInfo.List.Visible = false
script.Parent.GameInfo.Score.Visible = false
script.Parent.GameInfo.PauseButton.Visible = true --These are set to visible as they are shop, etc
script.Parent.GameInfo.ShopButton.Visible = true
script.Parent.GameInfo.ListOfPlayers.Visible = false
script.Parent.GameInfo.ListButton.Visible = true
script.Parent.Parent.Timer.Time.Visible = true
Player.char.HumanoidRootPart.CFrame = workspace.Spawns.HumanTP.CFrame --Is supposed to teleport the player to the part when the play button is clicked (This is another issue)
script.Disabled = true
end)
Yes, but the main problem is that the Player is supposed to spawn in a black box so no zombies attack them while they are in the main menu screen. However, upon running the game, the player spawns at the part that the script is meant to teleport them to when they click play