Change the speed of all players

Hi, How to make a script that changes the speed of all players in the game ? (without conditions)

To achieve this you would want to use a for loop like the one I have presented below

for _,v in pairs(game.Players:GetPlayers())do -- returns array of all players which you can iterate through
v.Character:WaitForChild('Humanoid').WalkSpeed = 50 -- changing walkspeed
end

You can read up some more on for loops here on the API

2 Likes

The best ideal source would be a player added function and then determine the character. Since all players will join at different time. I’d do it like this:

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:FindFirstChild("Humanoid").WalkSpeed = 50
	end)
end)
3 Likes

It’s dependent on situation whether this or different solution is ideal, what if OP wants to change the speed at a certain time not for every player that joins?

1 Like

If you don’t have any conditions, just add a humanoid into starterplayer and set it’s walkingspeed to your custom number

1 Like

He literally mentioned that he’d like to change a walk speed for all players. In condition if he’d like to change walk speed at certain point he would just have to use code above and create its own array with players that he’d like to change the walk speed.

No, he would just make a button with the script posted by @topdog_alpha and OP wouldn’t have to add any conditions.

You said an instance if he wouldn’t change the walk speed for all the players. The source code posted above mine is literally run only once and beside that it’s changing the walk speed for all the players.

If you don’t want to use conditions why not just use PlayerAddedEvent?

Thanks, but when someone dies, they lose their walk speed. I want when a player dies, I want him to keep 50 WalkSpeed

When a player dies, their character is deleted and replaced with a new character, this includes the Humanoid. So to combat this we need a way to know when the player gets a new character and set their WalkSpeed back to 50.

Fortunately Roblox has an event in the player object called CharacterAdded, this is fired whenever the player’s character spawns (or respawns).

You just need to put that into your code - which I am not going to tell you since you need to learn to solve problems like this yourself.

1 Like

Adding onto what Canopius said you would need to wrap the CharacterAdded event inside of a PlayerAdded event, because CharacterAdded requires a player object.

Mhhhh I tried with CharacterAdded and doesn’t work :confused:
because the player actually buys something that puts the WalkSpeed to everyone at 50, even when a player dies.

In that case just edit the StarterPlayer properties of your game. No need for a script. That way a humanoids walkspeed will always be the same and wont need editing

you don’t understand, when a player buys something that puts the WalkSpeed to everyone at 50, even when a player dies.

So you want someone to buy something, when it is bought everyone gets improved walkspeed? That is a condition

Oh… Yes x) Sorry ! My bad sorry

Get creative there are many ways you can fix this with loops you could check if a object in the workspace despawns and if so find a player object with the matching name then use the CharacterAdded event.

In that case you can use my original code that I posted but just put it inside a function that triggers when someone purchases the item like so:

game.RemoteEvent.OnServerEvent:Connect(function(plr) -- fire server when plr buys soemthign on UI
for _,v in pairs(game.Players:GetPlayers())do -- returns array of all players which you can iterate through
v.Character:WaitForChild('Humanoid').WalkSpeed = 50 -- changing walkspeed
end
end)

This only works for one life though.

Just put an if statement infront of what we have told you already and hook up some events.