Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Change Players Walkspeed at the same time?

So I want that all players change there WalkSpeed at the same time. With my script it circles trough each player and that takes a while, so other players can walk earlier then others.

    for i, player in pairs(plrs) do
        if player then
            character = player.Character

            if character then
                -- teleport them
                character:FindFirstChild("HumanoidRootPart").CFrame = AvailabelSpawnPoints[1].CFrame + Vector3.new(0,5,0)
				character.Humanoid.WalkSpeed = 0
                table.remove(AvailabelSpawnPoints,1)


                -- Give them a sword
                local Sword = ServerStorage.Sword:Clone()
                Sword.Parent = player.Backpack

                local GameTag = Instance.new("BoolValue")
                GameTag.Name = "GameTag"
                GameTag.Parent = player.Character

            else
                -- There is no character
                if not player then
                    table.remove(plrs,i)
					table.remove(charactersToMove,i)
                end
            end
        end
    end

    Status.Value = "Get Ready to play!"
	
	for ct = CountDownTimer,0,-1 do
		Status.Value = ct
		wait(1)
		
		if ct == 0 then
			character.Humanoid.WalkSpeed = 16
		end
	end

1 answer

✓ Accepted answer

From the looks of it, you're only setting the WalkSpeed to 16 for a single player, that is, the last player that was accessed by the loop above. To update the WalkSpeed for all players, you must use another for loop to go through all of them.

Additionally, you don't need to have the condition ct == 0, as this is also the condition where your loop ends. We can make the code with that condition execute after the countdown.

-- snip

for ct = CountDownTimer,0,-1 do
	Status.Value = ct
	wait(1)
end

-- Since this loop doesn't have anything that would yield (wait, WaitForChild, GetAsync, etc.),
-- all of it will be executed in the same game update cycle, and so all players' WalkSpeeds will
-- be updated at the same time
for i, player in pairs(plrs) do
	local character = player.Character
	if character then
		character.Humanoid.WalkSpeed = 16
	end
end

2 comments

0

Thank you very much! :)

1

No problem! Make sure to "Accept" my answer if you found it helpful.

This discussion is preserved as it was. New answers, comments, and votes are closed.