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.
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.