Answered by
4 years ago Edited 4 years ago
The reason why this error is happening is because Player.character should be Player.Character. By using Player.character, character is nil, which is why you cannot use WaitForChild.
1 | game.Players.PlayerAdded:Connect( function (Player) |
2 | Player.Character:WaitForChild( 'Humanoid' ).WalkSpeed = Player.leaderstats.RunSpeed |
Also you should be checking to make sure the player's character exists so that this does not error, like so. But if the player's character does not exist when the player is added nothing will happen, which is what happens in most cases.
1 | game.Players.PlayerAdded:Connect( function (Player) |
2 | local char = Player.Character |
4 | Player.Character:WaitForChild( 'Humanoid' ).WalkSpeed = Player.leaderstats.RunSpeed |
So the example below should help.
Alsoo, if you want the character's speed to always be edited even if they respawn, you should be using the CharacterAdded event of player like so
1 | game.Players.PlayerAdded:Connect( function (Player) |
2 | Player.CharacterAdded:Connect( function (char) |
3 | char:WaitForChild( 'Humanoid' ).WalkSpeed = Player.leaderstats.RunSpeed |
This way you no longer have to check if the character exists or not because the event only fires when a new one is added