"bhop" script speed bug

I made simple scripts for some “bunny hop”, but they either get in one way or one of them works. Sometimes when i change script sources in game and reload them, they only work after a restart.
This is their way:
scriptslocation
GetSpeed Source:

local hum = script.Parent.Humanoid
local runnow = script.Parent.RunningNow

while hum.Running do
    if hum.Jump then
        hum.Running:Connect(function(speed)
            if speed > .1 then
                hum.WalkSpeed += .1
            end
        end)
    end
    wait(.1)
end

LoseSpeed Source:

local hum = script.Parent.Humanoid

while not hum.Running do
    if hum.MoveDirection == Vector3.new(0, 0, 0) or not hum.Jump then
        for i = hum.WalkSpeed, game.StarterPlayer.CharacterWalkSpeed,-2 do
            script.Parent.Humanoid.WalkSpeed = i
            wait()
        end
    end
end

When i run my speed bugs and goes up and down.
I need the speed and fov to increase when i walk and jump, and when i stop or stop jumping, the speed smoothly decreases

3 Likes

while hum.Running do will likely never loop, remember that while loops check the condition, if it is false the while loop is skipped and since your script ends it will never be checked again.

-- Can be one script

-- Using jump event to gain speed
hum.Jumping:Connect(function()
	hum.WalkSpeed += 0.1
end)

-- while true will always loop, we then check movement direction
-- over and over again instead of at the start
while true do
	if hum.MoveDirection.Magnitude > 0 then -- running
		-- do nothing to keep speed
	else
		-- not running, lose speed
		for i = hum.WalkSpeed, game.StarterPlayer.CharacterWalkSpeed,-2 do
			script.Parent.Humanoid.WalkSpeed = i

			-- player is running again, stop losing speed
			if hum.MoveDirection.Magnitude > 0 then
				break
			end
			task.wait()
		end
	end
	task.wait()
end
3 Likes

thanks! it work, but if i stop jumping, speed will remain :frowning:

1 Like

For some reason I see the same thing! I think it is a roblox bug, try using hum.WalkSpeed = i

		for i = hum.WalkSpeed, game.StarterPlayer.CharacterWalkSpeed,-2 do
			hum.WalkSpeed = i