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.
1) WaitForChild
workspace:WaitForChild("Player") -- not recommended
2) CharacterAdded event
player.CharacterAdded:connect(function(character) print("Character loaded!") end)
3) Waiting for player.Character to not be nil
while not player.Character do wait() end