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 7 years ago
Edited 7 years ago
local character = game.Workspace.Player1
local player = game.Players:GetPlayerFromCharacter(character)

if player then
    print("Player is " .. player.Name)
else
    print("Player doesn't exist!")
end

1 answer

Log in to vote
0
Answered by
Omarstein 100
7 years ago
Edited 7 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 :)

local character = game.Workspace:WaitForChild("Player1")
local player = game.Players:GetPlayerFromCharacter(character)

if player then 
    print("Player is " .. player.Name) 
else 
    print("Player doesn't exist!") 
end

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 — 7y
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 — 7y
0
Ok thank you funkennethmbah 30 — 7y
Ad

Answer this question