Most of the script above is unnecessary because of how StarterCharacterScripts
works.
The basic concept behind StarterCharacterScripts
is that any descendant of it will get parented to a player's character whenever it spawns. Subsequently, once the character dies, the script is destroyed and parented again as soon as the player's character spawns.
This means we could boil down your code to the following:
1 | local Players = game:GetService( "Players" ) |
3 | local Player = Player.LocalPlayer |
4 | local Character = Player.Character |
5 | Character:WaitForChild( "Humanoid" ).WalkSpeed = 0 |
What does this mean for you? Well, once the player spawns, the Local Script inside of StarterCharacterScripts
will be cloned, and parented to the character. Once that happens, the script will run as a normal script. The humanoid will soon have it's walkspeed set to 0.
You might note I also added a small piece of code, namely the function WaitForChild
. When the script is parented to the player, he/she might not have yet fully loaded, so it's always a best practice to check if the object (in this case "Humanoid") is already present.
Good luck, and enjoy coding!