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

How would I make the Character get faster as it moves?

Asked by 6 years ago

What would I put in a script to make when the character moves it picks up speed? Would I use a loop to add to the players speed by increments?

2 answers

Log in to vote
0
Answered by
NsNidPL 41
6 years ago
Edited 6 years ago
local hum = script.Parent:WaitForChild("Humanoid")
local torso = nil

--check rig type
if hum.RigType == "R6" then
    torso = script.Parent.Torso
else
    torso = script.Parent.UpperTorso
end

while wait() do --put a number in the () if you want to slow down speed incerasing
    if torso.Velocity.Magnitude > 1 then
        hum.WalkSpeed = hum.WalkSpeed + 0.1 --this is how the walkspeed incerases
    else
        hum.WalkSpeed = 16 --default walkspeed
    end
end

Put this into StarterCharacterScripts. Works with R6 and R15.

0
Curious over here: Why did you set torso to nil? Is this required? EnlightenedDev 11 — 6y
0
Just in case. It is changed later based on the rig type. NsNidPL 41 — 6y
0
Thank You! Revisedy 23 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You should indeed use loops and use increments, It isn't done completely in a loop because it would add to the speed when the player isn't moving, script is below, the explenation is too, if you need some more explanation, feel free to ask (btw mark this as answered please xD)

Script needs to be in workspace

Increment = 1 -- It will become this much faster every time
DelayT = 0.1 -- It will wait this time before it starts the loop again
defSpeed = 5 -- Starterspeed, this number will change trough the loop
maxSpeed = 100 -- If you don't want this set it to 99999999999999999999999 or something like that xD
Speed = defSpeed
plrWalking = false

game.Players.PlayerAdded:connect(function(player) 
    player.CharacterAdded:connect(function(char)
        player.Character.Humanoid.Running:connect(function(speed)
            if speed > 0 then -- player isn't standing still
                plrWalking = true
            else
                plrWalking = false
            end
        end)
    end)
end)

while wait(DelayT) do

    for index, player in pairs(game.Players:GetPlayers()) do
        char = player.Character or player.CharacterAdded:wait()
        hum = char:WaitForChild("Humanoid")
        if hum and plrWalking and Speed < maxSpeed then -- if humanoid and player is walking
            print("plr is running")
            Speed = Speed + Increment
            hum.WalkSpeed = Speed -- increasing speed
        elseif not plrWalking then
            Speed = defSpeed
            hum.WalkSpeed = defSpeed -- reset speed when stopped
        end
    end
end

0
wow NsNidPL 41 — 6y
0
lol User#20388 0 — 6y
0
i need 25 reputation to upvote... what? how do i get reputation since other users havent got reputation and cant upvote... wait... is reputation based on upvoting? NsNidPL 41 — 6y
0
also wouldn't "inf" do the the trick in maxSpeed instead of 99999...? NsNidPL 41 — 6y
View all comments (3 more)
0
Thank you for also answering! Revisedy 23 — 6y
0
If you manually put in inf it doesn't work, so I don't think so xD User#20388 0 — 6y
0
can you make me one that works with the newest version of roblox? i tried this and it did not work. therealdood35 -5 — 5y

Answer this question