Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

3 comments

0

Thank you so much also how do you change my text into code format?

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.

0

Ok thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.