BodyVelocity changing itself

Im creating a cricket system and trying to make the ball bounce, it works, but only half the time, sometimes it will roll along the ground

the way it works is that a while loop continually minuses the bodyvelocity’s x axis to stimulate gravity, and when the ball hits the pitch it adds a number to make the ball bounce, but sometimes it sets it and is positive for a second ,then goes back to negative (the image attached is printing the velocity

this is the script to make it bounce (sorry for the really messy coding and weird calculations
all this is doing is getting the part from the pitch’s value inside of it and using that value to make the bounce higher and then add on to that value, it then changes the parts colour afterwards. After thats done it adds a tenth of the balls speed with the pitch’s bounce value onto the base bounce value and then it sets it to the ball’s velocity

	db = true
				firstbounce = true
				bounceval =(basebounce + (ball.Velocity.Magnitude/10) + (hit.Bounce.Value))
				hit.Bounce.Value += .5
				hit.Color = Color3.new(hit.Color.R - hit.Bounce.Value/8,hit.Color.G - hit.Bounce.Value/8,hit.Color.B - hit.Bounce.Value/8)
				ball.BodyVelocity.Velocity = Vector3.new(ball.BodyVelocity.Velocity.X,bounceval,ball.BodyVelocity.Velocity.Z)
				print(ball.BodyVelocity.Velocity)
				spawn(function()
					wait(1)
					db = false
				end)

this is just doing the gravity stuff

while ball:FindFirstChild("BodyVelocity") and wait() do
	if ball:FindFirstChild("BodyVelocity") then
		print(ball.BodyVelocity.Velocity)
		ball.BodyVelocity.Velocity = ball.BodyVelocity.Velocity + Vector3.new(0, gravity * heartbeat:Wait(), 0)
	end
end