How to change all players walkspeed using a script?

Yeah it works, what about you put it in a Loop?

Use this.
Put it in ServerScriptService

local WalkSpeed = -- Your value here
game.Players.PlayerAdded:Connect(function(player)
    player.CharactedAdded:Connect(function(character)
        character.Humanoid.WalkSpeed = WalkSpeed
    end)
end)
1 Like

He said he don’t want to set the player’s speed using PlayerAdded event…

I want to be able to change the walkspeed later on in the script, don’t think this would work for that.

I put it inside of a while true loop however, it still seems not be working.

When do you want the Walkspeed to change?

What the code I gave you do is:

  • It loops through all the players.
  • It indexes every player’s character.
  • Then it finds Humanoid in the character and sets the WalkSpeed to the number assigned.

if you’re talking about a sprint script that’s a local script thing not a global script

what you can do is fire a remote to all clients to toggle the run though

Show us your code

30chars im really sorry but i have to do this like i said in another post i cant use heart because then they wont get what im trying to say !!!

how do I use markdown I want to reply a script

try this:

for i,v in pairs(game.Players:GetChildren()) do
v.CharacterAdded:Connect(function()
v.Character.Humanoid.Walkspeed = 20
end)
end

He don’t want it when player spawn or join the game.

alright then he can try this

for i,v in pairs(game.Players:GetChildren()) do
v.Character.Humanoid.Walkspeed = 20
end
local Walkspeed = 20 -- change it to whatever you want
for index, value in pairs(game.Players:GetChildren()) do
   value.Character.Humanoid.WalkSpeed = Walkspeed
end

I’m trying all the scripts, non of them have worked for some reason. Not sure if this makes a difference but i’m changing the players walkspeed because I need it for a ‘Game Starting’ part and I don’t want the player to have the ability to move, but then eventually once the countdown has finished I then want the players to have the default walkspeed of 16.

well i’m just gonna try the discord markdown then

--localscript

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(key,gpe)
 if gpe then return
 if key.Keycode == Enum.Keycode.LeftShift then
  -- fetch sprint remote in replicatedstorage
  game.ReplicatedStorage.Sprint:FireServer("began")
 end
end)

uis.InputEnded:Connect(function(key,gpe)
 if gpe then return
 if key.Keycode == Enum.Keycode.LeftShift then
  -- fetch sprint remote in replicatedstorage
  game.ReplicatedStorage.Sprint:FireServer("ended")
 end
end)


--serverscript 
local default = 20
local newSpeed = 25
local actions = {
 ["began"] = function(target)
  local ch = target.Character
  repeat wait() until ch ~= nil
  local hum = ch:FindFirstChildOfClass("Humanoid")
  hum.WalkSpeed = newSpeed
 end,
 ["ended"] = function(target)
  local ch = target.Character
  repeat wait() until ch ~= nil
  local hum = ch:FindFirstChildOfClass("Humanoid")
  hum.WalkSpeed = default 
 end
}
game.ReplicatedStorage.Sprint.OnServerEvent:Connect(function(player,args)
 actions[args](player)
end)
for index, player in ipairs(game:GetService("Players"):GetPlayers()) do
   if player.Character and player.Character:FindFirstChildWhichIsA("Humanoid") then
       player.Character.Humanoid.WalkSpeed = 20 -- New value.
   end
end

Are you waiting though? If you run the code right when the server runs, the player might not load and it will be for nothing.

I would recommend using i, v in pairs for this. Here’s an example:

local plrs = game.Players:GetChildren()

wait(5) --Gives players a chance to load.

if #plrs >= 1 then --Makes sure there's a player.
	for i, v in pairs(plrs) do
		v.Character.Humanoid.WalkSpeed = 20 --Change to whatever you want.
		print(v.Name.."'s WalkSpeed was changed!") --You can remove this if you want.
	end
end

I know I’m responding to this over a year later… But I found why @focasds script wasn’t working.
16 is the default player walk speed. All that was wrong with his script was that the walk speed was changing to it’s original value. Simply have a different variable for the speed you want the player to go.

Changing the speed to 40:

local Speed = 16
local SuperSpeed = 40

for i, Player in pairs (Players:GetChildren()) do
	local Character = Player.Character
	Character.Humanoid.WalkSpeed = SuperSpeed -- SETS PLAYER SPEED TO 40

Changing the speed back to the standard player speed:

local Speed = 16
local SuperSpeed = 40
for i, Player in pairs (Players:GetChildren()) do
	local Character = Player.Character
	Character.Humanoid.WalkSpeed = Speed -- RESETS PLAYER SPEED

oh but if you need to set speed from moment when player joins its too easy:
first we need to open Game settings
and go to here
изображение_2021-09-19_090127
then will open this menu
and here it is

1 Like