Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I keep getting this error - Player1 is not a valid member of Workspace, Can anyone help me?

Asked by 8 years ago
Edited 8 years ago
1local character = game.Workspace.Player1
2local player = game.Players:GetPlayerFromCharacter(character)
3 
4if player then
5    print("Player is " .. player.Name)
6else
7    print("Player doesn't exist!")
8end

1 answer

Log in to vote
0
Answered by
Omarstein 100
8 years ago
Edited 8 years ago

One way to fix this would be to use :WaitForChild() now I'm not sure if this is the best method, but it works :)

1local character = game.Workspace:WaitForChild("Player1")
2local player = game.Players:GetPlayerFromCharacter(character)
3 
4if player then
5    print("Player is " .. player.Name)
6else
7    print("Player doesn't exist!")
8end

Elaborate The error "Player1 is not a valid member of Workspace" is displaced because the script ran before the character loaded, so the player wasn't part of Workspace.

0
Thank you so much also how do you change my text into code format? funkennethmbah 30 — 8y
0
When you post/edit the question there is a Lua code logo on top of the textbox where you write the question, click on it and put your code in the middle. Omarstein 100 — 8y
0
Ok thank you funkennethmbah 30 — 8y
Ad

Answer this question