How to change all players walkspeed using a script?

What I want to achieve?
I want a script that changes the walkspeed when run. I don’t want the speed set when playeradded or anything.

What’s the issue?
I have looked all over google and devforum but I not able to find something that matches my needs.

2 Likes

Would this just change the walkspeed property for the user mentioned? I want the script to change the walkspeed for all users.

1 Like

If you would like to change everybody’s speed at the same time just do this:

local Players = game:GetService("Players")
local Speed = 16

for i, Player in pairs (Players:GetChildren()) do
      local Character = Player.Character
      Character.Humanoid.WalkSpeed = Speed
end
2 Likes

Doesn’t seem to be working for me. I’m using a script in ServerScriptService, would this work in this 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)