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

how to change walkspeed?

how does one make the player's walkspeed increase every few steps/ seconds? I'm trying to make a game similar to running simulator but can't figure out how to make the walkspeed increase. also, how do you make it to where if the walkspeed is higher, it takes longer to increase the walkspeed? Thanks in advance.

1 answer

local Walking = false
local Character = script.Parent
local Humanoid  = Character:WaitForChild("Humanoid")

local Speed = game:GetService("Players"):GetPlayerFromCharacter(Character):WaitForChild("leaderstats"):WaitForChild("Speed")

function onWalking(CurrentSpeed)
	if CurrentSpeed > 0 then
		Walking = true
		spawn(function()
			while Walking do
				Speed.Value = Speed.Value + 1
				Humanoid.WalkSpeed = Speed.Value
				wait(.25)
			end
		end)
	else	
		Walking = false
	end
end

Humanoid.Running:Connect(onWalking)

In the code above we declare four variables, one is a boolean for if the player is walking, another is for the character, another is for the humanoid, and another is a leaderstat called Speed. We have a function that is connected to the Running event of the humanoid. Once the function is called then we check if the CurrentSpeed is greater than 0, and if that's the case we set walking to true and we make a loop that repeats until walking is false. What it does is that it increases speed by 1 and changes the humanoid's speed to the value of speed, and it does this every .25 seconds. If the function is called again but CurrentSpeed is less than or equal to 0 then it sets walking to false. I have not tested this code but it should work. It should also be located in StarterCharacterScripts.

2 comments

0

it works however for some reason its increasing however its not doing it every .25 seconds

0

im trying to fix this

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