Changing the players walkspeed when they join

So basically I wan’t it so when the player joins his/her walkspeed is set to 0 until they click the play button. I’ve tried doing this myself however it just doesn’t work somehow.

I have a sever script with the following code in it:

game.Players.PlayerAdded:Connect(function(plr)
plr.Character.Humanoid.Walkspeed = 0
end)

4 Likes

You need to wait for the character to load before you can do anything with that. You can use the CharacterAdded event:

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
character.Humanoid.Walkspeed = 0
end)
end)
2 Likes

Still did not work. No errors but the players walkspeed is still the default.

1 Like

Adding on to what @ThomasChabot said, you would also want to wait for the humanoid to spawn in of course

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hum = character:WaitForChild(“Humanoid”)
hum.WalkSpeed = 0
end)
end)

2 Likes

Thank you!!. This worked very well.

How do I fix this so it doesn’t reset and change the players walkspeed back to 0 when he/she dies or resets?

You could add a Humanoid.Died event to wait for the character to respawn, and then change their walkspeed.

The example code below covers it.

game.Players.PlayerAdded:connect(function(Player)
  Player.CharacterAdded:connect(function(Character)
    local Humanoid = Character:WaitForChild("Humanoid")
    Humanoid.Died:connect(function()
      local Char = workspace:WaitForChild(Player.Name)
      if Char ~= nil then
        Char:WaitForChild("Humanoid").WalkSpeed = 0
      end
    end)
end)
1 Like

I put that in the script and nothing happened. The walkspeed is default now.

Oh, my bad. I overcomplicated my code a bit. Try this.

game.Players.PlayerAdded:connect(function(Player)
  Player.CharacterAdded:connect(function(Character)
    local Humanoid = Character:WaitForChild("Humanoid")
    Humanoid.Died:connect(function()
      repeat wait() until Character ~= nil -- ik it's inefficient.
      Character:WaitForChild("Humanoid").WalkSpeed = 0
    end)
end)

It stills sets the players walkspeed to 16/default. https://gyazo.com/a74a2f361dc0abddba91f825b450489e

No errors in dev console though.

What is the point of making a script for it? You can just change it in StarterPlayer service properties.

1 Like
game.Players.PlayerAdded:connect(function(Player)
  Player.CharacterAdded:connect(function(Character)
    Character:WaitForChild("Humanoid").WalkSpeed = 0
  end)
end)

It’s only useful if the WalkSpeed is planned to change at some point.

(i.e I wouldn’t imagine @danthespam permanently making players stuck, in this case anyway)

1 Like

Yes. Also the code above still didn’t work.

try the code again. i edited it YET again

There is a property in StarterPlayer called “CharacterWalkSpeed”. This could potentially be useful for your inquiry.
image

2 Likes

Your code worked but it still resets back to 0 once the player has died or resets

I only wan’t the players walkspeed to be 0 once.

game.Players.PlayerAdded:connect(function(Player)
  local CA
  CA = Player.CharacterAdded:connect(function(Character)
    Character:WaitForChild("Humanoid").WalkSpeed = 0
    CA:Disconnect()
  end)
end)
3 Likes

This code worked. Thank you very much!

1 Like