Change the speed of all players

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.

In that case change everyone’s walk speed AND connect the CharacterAdded event. To then stop the increased walkspeed simply disconnect the event.

1 Like

You could also add a value to the player object and check it if it = true then you can give them walkspeed back.

You can use a boolvalue:

while true do
      wait()
     if game.ReplicatedStorage.Speed.Value == true then
     for i,v in pairs(game.Players:GetChildren()) do
           v.Character:WaitForChild("Humanoid").WalkSpeed = 50
     end
end
end

Can I know how your buying script works? These suggestions are useful, but I want to be sure on how your buying system is.

1 Like

I’ve found the solution, you don’t have to help me anymore! I just added one: NumberValue

1 Like

I would not recommend that you use a while wait()/true do loop you can find more here.

If you really want a loop, use the Heartbeat event from the RunService, however this is not very performant, setting the walk speed every frame when you don’t need to.

All the OP needs to do is when the player buys the powerup is loop through all of the players changing their walk speed and connecting the character added event to a function that also increases the walk speed.

1 Like