Blade ball deflection issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it so if you deflect the ball early, once it comes to you quick enough, then it is deflected.
  2. What is the issue? Include screenshots / videos if possible!
    I can only make it so that if you are in range then you just deflect it.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried using runservice and loops.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

In blade ball, if you block early, once the ball comes to you before there is a cooldown, you can deflect the ball. I want that to happen to my game, however, I can’t figure out how to do it. I tried using runservice and loops, but those only caused bugs.

UIS.InputBegan:Connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and Canhit and char.Humanoid.Health > 0 then   

		local BallSpeedRemote = Repstorage:WaitForChild("GetBallspeed")

		local Ball = BallSpeedRemote:InvokeServer()
		Canhit = false
		
		Hitting = false
		local Highlight = Instance.new("Highlight")
		Highlight.FillColor = Color3.new(1, 1, 1)
		Highlight.Parent = char

		workspace["Sword_Draw_Sound_Effect (1)"]:Play()

		local initialPosition = Ball.ball.Position
		local targetPosition = char:FindFirstChild("HumanoidRootPart").Position
		local distance = (targetPosition - initialPosition).Magnitude

		local speed = Ball.ballspeed * 25
		
		if Ball.Target == char.HumanoidRootPart and char.Humanoid.Health > 0 then
				local Origin = ball 
				local End = char.HumanoidRootPart
				local Direction = (End.Position - Origin.Position).Unit 

				local Params = RaycastParams.new() 

				Params.FilterType = Enum.RaycastFilterType.Include
				Params.FilterDescendantsInstances = {Origin, End}
			
				local Result = workspace:Raycast(Origin.Position, Direction * 1000, Params)  
				
				if Result and Result.Distance <= 15 and char.Humanoid.Health > 0 and Ball.Target == char.HumanoidRootPart then
					if not Hitting  then
					Canhit = true
					Hitting = true

					BallEvent:FireServer()
			
					workspace.Score_Sound_Effect:Play()

					task.wait(0.2)

					Deletehighlight()

					Hitting = false
					end
				end
		end
			
			task.wait(1)
			
			if not Hitting and not Canhit then  
				Canhit = false
				Deletehighlight() 
				task.wait(1) 
				Canhit = true
			end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.