Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Changing speed OnEnter?

Asked by 9 years ago

Apparently this does not work. It is line 2 with the error.

game.Players.PlayerAdded:connect(function()
    script.Parent.Character.Humanoid.WalkSpeed = 20
end)

F.Y.I the script is in workspace

2 answers

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

For this script, you will also want to connect the player added function to the character added function. PlayerAdded will only work on when you first join the game, with the CharacterAdded function, you can reset over and over and still get that speed, plus it's easier to connect to character. For the PlayerAdded function you wanted to define the player, that goes the same with the CharacterAdded function. And script.Parent would not have worked in workspace since there is no speed property for the workspace.

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(character)
    character.Humanoid.WalkSpeed = 20
end)
end)
Ad
Log in to vote
0
Answered by
war8989 35
9 years ago

You have to wait until the player's character is added to update their WalkSpeed, do the following:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        char.Humanoid.WalkSpeed = 20
    end)
end)

Answer this question