So i made a KnockBack sistem but it's just off

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 would just like some feedback from someone about the knockback sistem that i made here, it just seems off.

  2. What is the issue? Include screenshots / videos if possible!
    Probably there are some issues in regarding the whole writing of the script and also the way i detect the force based on the percentage of the script.So will be grateful to everyone that would take some time to check the script.I was trying to imitate the knockback sistem from the TSB or the Project Smash

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried rewriting it a whole lot of times, but this is the best i was able to achieve so far.

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!

-- function KnckBackModule.KnockBackPlayer(achar, bchar)
	
	if not achar or not bchar then
		return
	end
	
	local aHrp = achar:FindFirstChild("HumanoidRootPart")
	local bHrp = bchar:FindFirstChild("HumanoidRootPart")
	local bHum = bchar:FindFirstChild("Humanoid")
	
	if not aHrp or not bHrp or not bHum then
		return
	end
	
	local hitBall = Instance.new("Part")
	hitBall.Position = bHrp.Position
	hitBall.Shape = Enum.PartType.Ball
	hitBall.Size = Vector3.new(6,6,6)
	hitBall.Transparency = .4
	hitBall.Massless = true
	hitBall.Parent = bHrp
	
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = bHrp
	weld.Part1 = hitBall
	weld.Parent = bHrp
	
	local lockGyro = Instance.new("BodyGyro")
	lockGyro.MaxTorque = Vector3.new(1e6, 1e6, 1e6)
	lockGyro.CFrame = hitBall.CFrame
	lockGyro.Parent = hitBall

	local KBpercentage =  bHrp.Attachment.KnockBackGUI.lblNumber.Text
	local maxKBvalue = 200
	
	local minTimer =  .3
	local maxTimer = 1
	local KBDuration = math.clamp(minTimer + (KBpercentage / maxKBvalue) * (maxTimer - minTimer), minTimer, maxTimer)
	local decreaseRate = KBDuration / 10

	local minR = 0.8
	local maxR = 3
	local r = math.clamp(maxR - (KBpercentage / maxKBvalue) * (maxR - minR), minR, maxR)

	-- Knockback calculation parameters
	local DataTable = {
		d = 10, -- Damage scaling factor
		s = KBpercentage / 100, -- Scaling based on knockback percentage
		b = 15, -- Base knockback
	}


	-- Add upward component to the trajectory
	local knockBackFormula = ((((((KBpercentage / 10) + (KBpercentage * DataTable.d / 20)) * 1.4) + 18) * DataTable.s) + DataTable.b) * r
	local direction = (bHrp.Position - aHrp.Position).Unit
	local upwardForce = Vector3.new(0, knockBackFormula * 0.3, 0) -- Adjust upward force multiplier as needed
	local velocity = direction * knockBackFormula + upwardForce
	
	
	print("KnockBack Formula: ", knockBackFormula)
	print("KnockBack Multiplier r: ", r)
	print("Timer is: ", KBDuration)
	print("The velocity is :", velocity)
	
	local isDummy = game.Players:GetPlayerFromCharacter(bchar) == nil
	
	if not isDummy then
		bHrp:SetNetworkOwner(nil) -- Temporarily assign ownership to the server
		bHrp:SetNetworkOwnershipAuto(false)
		bHum:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
		bHum:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
	end

	
	-- Create and apply BodyVelocity
	local bodyVelocity = Instance.new("BodyVelocity")
	bodyVelocity.Velocity = velocity -- Set velocity based on knockback calculation
	bodyVelocity.MaxForce = Vector3.new(1e6, 500, 1e6) -- Allow sufficient force to overcome resistance
	bodyVelocity.P = 1000 -- Adjust power if needed for responsiveness
	bodyVelocity.Parent = bHrp -- Attach to target's root part

	bHum.PlatformStand = true

	--KBEffectsEvent:FireAllClients(bHum, KBDuration)
	
	
	Debris:AddItem(bodyVelocity, KBDuration / 2)

	task.delay(KBDuration, function()
		local initialVelocity = bHrp.AssemblyLinearVelocity
		print(initialVelocity)
		
		for i = 0, KBDuration, decreaseRate do

			-- Linearly interpolate the velocity
			local t = i / KBDuration -- Progress ratio (0 to 1)
			local newVelocity = initialVelocity:Lerp(Vector3.zero, t)

			-- Apply the new velocity
			bHrp.AssemblyLinearVelocity = Vector3.new(newVelocity, bHrp.AssemblyLinearVelocity.Y, newVelocity)
			-- Wait for the decreaseRate duration before the next step
			task.wait(decreaseRate)

		end
		
		hitBall:Destroy()
		weld:Destroy()
		
		bHrp.AssemblyLinearVelocity = Vector3.zero
		bHum.PlatformStand = false
		bHum:ChangeState(Enum.HumanoidStateType.PlatformStanding)
		if not isDummy then
			bHrp:SetNetworkOwnershipAuto(true) -- Return ownership to the player
		end

	end)
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.