Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to change walkspeed?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
4 years ago
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.

0
it works however for some reason its increasing however its not doing it every .25 seconds Mr_Unlucky 1085 — 4y
0
im trying to fix this Mr_Unlucky 1085 — 4y
Ad

Answer this question