Why am I getting this error?

Im trying to make it so that the player gains momentum and starts to run.

But whenever I stop running, my walkspeed is still 24.

How do I fix this?

while task.wait() do
	local result = isKeyDown()
	print(result)
	print(humanoid.WalkSpeed)
	if humanoid then
		if humanoid.WalkSpeed == 16 then
			if result then
				for i = 1, 10 do
					if humanoid.WalkSpeed == 24 then
						break
					end

					task.wait(0.004)
					humanoid.WalkSpeed += 0.8
					humanoid.WalkSpeed = math.round(humanoid.WalkSpeed)
				end
			end
			
			if not result then
				for i = 1, 10 do
					if humanoid.WalkSpeed == 16 then
						break
					end

					task.wait(0.004)
					humanoid.WalkSpeed -= 2
				end
			end
		end
	end
end

what is the isKeyDown() function?

Your first if-statement if humanoid.WalkSpeed == 16 then prevents the second part of your loop which is intended to subtract walkspeed for ever running. Try moving the if not result then part outside of the if humanoid.WalkSpeed == 16 check.

1 Like