Football/Soccer Dribbling System Bug - Ball stops in front

  1. What do you want to achieve?
    I’m trying to create a smooth dribbling system, in this case I’m trying to keep the ball loose when dribbling but when I look forward at the ball and dribble straight forward, the ball doesn’t go further than 3-4 studs.

  2. What is the issue?
    It works just fine and I’ve come up with the script however the ball sort of stutters and stops abruptly after 1-2 dribbles, and repeats. It stays in the position I want, however once the ball gets sort of frozen/stopped, I can’t dribble it during that time and it doesn’t feel smooth.

  3. What solutions have you tried so far?
    I’ve tried to find solutions to this everywhere but I just can’t find any and don’t know what to look at since I’ve also tried replacing the method I use to detect if the ball is in front.

Here is all of the code for my dribble function.

function kicks.dribble(increase)
	local ball = getNearestBall()
	if ball and PlayerMoving() then
		changeBallOwner(ball, false)

		if ball then
			local ownerHRP = currentBallOwner.Character and currentBallOwner.Character:FindFirstChild("HumanoidRootPart")
			local ballPosition = ball.Position

			if ownerHRP then
				local playerFacingDirection = hrp.CFrame.LookVector
				local playerToBall = (ballPosition - ownerHRP.Position).Unit

				local dotProduct = playerFacingDirection:Dot(playerToBall)
				if dotProduct > 0.4 then
					local distance = (ownerHRP.Position - ballPosition).Magnitude
					if distance > 3 then
						local maxForwardDistance = 3
						local limitedDribbleVelocity = playerToBall * maxForwardDistance

						ball.AssemblyLinearVelocity = limitedDribbleVelocity
						return
					end
				end
			end
		end

		local playerFacingDirection = hrp.CFrame.LookVector
		local dribbleVelocity = playerFacingDirection * increase * 32

		ball.AssemblyLinearVelocity = dribbleVelocity

		game:GetService("SoundService").Dribble:Play()
		if animationState == 1 then
			dribble1:Play()
			animationState = 2
		elseif animationState == 2 then
			dribble2:Play()
			animationState = 1
		end
	end
end