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

Changing players walkspeed in server script?

So I'm making an elevator game and for a floor I want everyone to run fast to do a speed run but the main code in it won't change the walk speed, Can anyone help?

Here's my code

local timeLimit = script.Parent:FindFirstChild("TimeLimit")

if workspace:WaitForChild("SpeedRun") then
	for i,v in pairs(game.Players:GetChildren()) do
		v.Character.Humanoid.WalkSpeed = 24
		wait(timeLimit)
		v.Character.Humanoid.WalkSpeed = 16
	end
end

1 answer

✓ Accepted answer

The problem here is that when the for loop loops through, it waits for the time limit every time. So it changes a player's movespeed, then waits a long time, then moves on to the next player. Instead you want something like this:

local timeLimit = script.Parent:FindFirstChild("TimeLimit")
 
if workspace:WaitForChild("SpeedRun") then
	for i,v in pairs(game.Players:GetChildren()) do
		v.Character.Humanoid.WalkSpeed = 24
	end

	wait(timeLimit)

	for i,v in pairs(game.Players:GetChildren()) do
		v.Character.Humanoid.WalkSpeed = 16
	end
end

It changes the speeds, waits for the time limit, then changes the speeds back.

1 comment

0

Timelimit is a intvalue that tells the script how long it needs to wait until the floor has to stop for example like a beach the value of time limit is 15 then it waits 15 seconds until the floor will be deleted and the doors of the elevator close but at local timeLimit I just had to add value to it

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