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!?
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!?
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.
workspace:WaitForChild("Player") -- not recommended
player.CharacterAdded:connect(function(character)
print("Character loaded!")
end)
while not player.Character do
wait()
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
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.
Thanks for the heads up