There are a few issues with your code; I will try as best I can to go through step by step as to what I did to fix it. Below is the working code.
1 | game.Players.PlayerAdded:connect( function (p) |
2 | p.CharacterAdded:connect( function (char) |
3 | local humanoid = char:WaitForChild( "Humanoid" ) |
4 | humanoid.Walkspeed = 18 |
1.) The listening event CharacterAdded only works on an active player, not on Workspace. If you wanted something to detect when objects enter workspace, ChildAdded is the way to go. To fix this, I simply added another anonymous function before CharacterAdded that detected players being added to game.Players.
2.) The third line of my code, after the functions were stated, defines the humanoid variable you wanted. While you did write out the userdata for the Humanoid, there were a few logic errors in doing this.
First, you didn't state the name of the variable. You simply wrote out userdata values, and this won't do you any good. Set it equal to a name like humanoid, and make it local to conserve script bandwidth.
Second, the userdata for this was incorrect. Player is not inside Workspace; it's a part of game. I fixed this by using char, since char is the variable I chose to represent the character being added; you can name this variable whatever you want.
Third, I noticed a syntax error, whenever you use :WaitForChild(), always use quotations for what is inside the parentheses. This method only accepts string values, so Humanoid would cause an error.
Fourth, you had conflicting conceptions. When you WaitForChild(), the program yields..Indefinitely.. until a descendant is found with a name of that string value. The if statement is useless when you do this because if that WaitForChild has unyielded, that means that you've found a Humanoid, so there's no guessing as to whether the Humanoid is there or not! I would also like to point out that if you did run that if statement, it would have had an error because of that userdata.
3.) This was a repeated error of misconstrued userdata, but I just wanted to point out that I used the humanoid variable I referenced on the line before to change the Walkspeed, instead of typing this line of userdata out again. It is generally a good rule in scripting to repeat userdata as little as possible.
I hope this helped, and if it did, make sure to upvote!