For some reason, It says attempt to index nil with 'WaitForChild' Can somebody help me out?
game.Players.PlayerAdded:Connect(function(Player) Player.character:WaitForChild('Humanoid').WalkSpeed = Player.leaderstats.RunSpeed end)
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.
game.Players.PlayerAdded:Connect(function(Player) Player.Character:WaitForChild('Humanoid').WalkSpeed = Player.leaderstats.RunSpeed end)
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.
game.Players.PlayerAdded:Connect(function(Player) local char = Player.Character if char then Player.Character:WaitForChild('Humanoid').WalkSpeed = Player.leaderstats.RunSpeed end end)
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
game.Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(char) char:WaitForChild('Humanoid').WalkSpeed = Player.leaderstats.RunSpeed end) end)
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
Player.character:WaitForChild('Humanoid').WalkSpeed = Player.leaderstats.RunSpeed
the second line on humanoid should be " " so use this script instead
Player.character:WaitForChild("Humanoid").WalkSpeed = Player.leaderstats.RunSpeed