How to gain speed when you keep walking?

I’m looking to create a script: the more you walk, the more you get faster until you’re at a certain speed, and when you stop, it stops the speed and you have to restart running.
Is there a chance there could be a script for that? If so, please kindly give the whole script (I’m fairly new at scripting so there’s no chance I can understand only bits of information for the script).

For conclusion, if you don’t understand what I mean, let me put it in context for you: The longer time you walk, you speed up so that you’re faster than what you originally started. It stops the fast speed and you have to restart running to regain the speed.

2 Likes

You could use GetPropertyChangedSignal to detect when the player is moving

example:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		local Humanoid = Char.Humanoid
		Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
			if Humanoid.MoveDirection == Vector3.new() then Humanoid.WalkSpeed = 16 end 
			Humanoid.WalkSpeed += 5
		end)
	end)
end)
3 Likes

Thank you for your help, but unfortunately it won’t work. I forgot to mention that I want the script to work on players that have a char to be a character/model. Is there any other script I could use to solve my problem?

Add a simple .Running function

Running:

local speedToGive = 5
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
         Char.Humanoid.Running:Connect(function(speed)
             if speed > 0 then Char.Humanoid.WalkSpeed = Char.Humanoid.WalkSpeed + speedToGive end
        end)
    end)
end)
1 Like

Why wont it work? It works fine, it should be a Script on the server

1 Like

I’m unsure, but I will try to solve it right now.

Put this in a local script in StarterPlayer/StarterCharacterScripts

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
while task.wait() do
    if humanoid.MoveDirection == Vector3.new() then
        humanoid.WalkSpeed = 12
    else
        humanoid.WalkSpeed += 1
    end
end
2 Likes

By the way, ‘char’ is the player’s character. We use CharacterAdded event ,so that it’ll fire each time the player’s character is in-game.

1 Like

Instead of a loop, you could use GetPropertyChangedSignal()

1 Like

but move direction doesn’t change over time and would fire non-linearly. from my understanding they want the speed to gain over time, not the more you change direction.

1 Like

oh a server script? kk it works good but how do you make it stop when your at a certain speed?

GetPropertyChangedSignal() only emits if its a large value (im not sure why but due to this feature people made an teleport detection using CFrame getpropertychangedsignal on cframe)

1 Like

add

if humanoid.WalkSpeed > limit then
    return
end
1 Like

This is incorrect, GetPropertyChangedSignal() emits when the property is changed; with MoveDirection it will be a unit circle (x, z).magnitude <= 1 or less if using analog controls this is useful for changes when you only care about when the player’s movement direction changes. I’ve found use for it in simple custom controls for physics objects, changing a Vector force to match the movement direction instantly makes a simple physics based movement system for whatever it is attached to. For this example it doesn’t make sense as we don’t care what direction the player is going, just how long they have been moving.

But if you do that, your speed will not gain afterwards.