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

Roblox is telling me Players is not a valid member of Workspace. Why?

I put in this code:

Workspace.Player.Humanoid.Health = 0

and when I run it Roblox comes up with this error:

22:28:21.376 - Player is not a valid member of Workspace

WHY!?

Note: Yet when I put in a wait it seems to work perfectly fine. WHY!?

2 comments

0

Well obviously the code is running before the player is in, so that's why it works with the wait. Just a heads up, this won't work in online mode.

0

Thanks for the heads up

1 answer

✓ Accepted answer

The player doesn't get added to the workspace immediately.

To wait for a player to be loaded into the workspace, you have a few options.

  1. WaitForChild
workspace:WaitForChild("Player") -- not recommended
  1. CharacterAdded event
player.CharacterAdded:connect(function(character)
	print("Character loaded!")
end)
  1. Waiting for player.Character to not be nil
while not player.Character do
	wait()
end

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