"char is not a valid member of (Player name here)"

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)
1 Like

Replace Player.char with char.

It’s trying to find the property/key in Player named char, Char isn’t a valid property.

1 Like

Should be char. Also, why are you defining a players character twice?

After I did what you said, the error in output was gone, but the player still was not teleporting to a different part when I clicked the play button

Instead, It teleports to the part without me clicking play

I uh, recommend you try and rewrite your code, I can barely read it because of the spacing and there are repeated values that a bascially useless

char.HumanoidRootPart.CFrame = workspace.Spawns.HumanSpawn.CFrame

Sure this line doesn’t have an effect on it?

HumanSpawn is the spawn part, and HumanTP is the part people teleport to when clicking the button

And the two parts are far from eachother

Ill see what happens if I remove the line

Blockquote

HmmmTheUnderratedDevProgrammer

KillzIsSomeRandomGuy

15m

char.HumanoidRootPart.CFrame = workspace.Spawns.HumanSpawn.CFrame

Sure this line doesn’t have an effect on it?

I removed the line, and still no fix

Ah, not sure about the issue then.

You would have to do some debugging, with prints and etc.

You set char as a variable twice


local char = Player.Character or Player.CharacterAdded:Wait() --Gets the character of the player

local char = Player.Character

I removed one of the two variables and still no fix

And also replace all Player.char with char as mentioned by @MixedConscience

I also did that. Is there any other way this problem could be fixed?

Have you removed local Character = Player.Character or Player.CharacterAdded:Wait()?

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

can you tell me what exactly the issue is ? I’ve been looking trough posts and i see that your first issue is solved, what now ?

The issue is explained above your reply