How to add knockback to a punch

here is the server script, let me know if u need the local script ( u probably dont need that becuz its just hitbox and animation based )

server script:

local rs = game:GetService("ReplicatedStorage")

local events = rs:WaitForChild("Events")
local hitboxEvent = events:WaitForChild("Hitbox")



function newHitbox(character, size, offset, damage, linger)
	local hrp = character:FindFirstChild("HumanoidRootPart")
	if hrp == nil then return end
	local weld = Instance.new("WeldConstraint", hrp)
	local hitbox = Instance.new("Part")
	weld.Part0 = hrp
	weld.Part1 = hitbox

	hitbox.Transparency = 1
	hitbox.CanCollide = false
	hitbox.CanQuery = false
	hitbox.Massless = true

	hitbox.Size = size
	hitbox.CFrame = hrp.CFrame + hrp.CFrame.LookVector * offset.X + Vector3.new(0,offset.Y)
	hitbox.Parent = character

	hitbox.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") == nil then return end

		for _, v in pairs(hitbox:GetChildren()) do
			if v:IsA("ObjectValue") then
				if v.Value == hit.Parent then return end
			end
		end

		local hitCounter = Instance.new("ObjectValue", hitbox)
		hitCounter.Value = hit.Parent

		hit.Parent.Humanoid:TakeDamage(damage)
		
		local sound = script.Sound:Clone()
		sound.Parent = hit.Parent:FindFirstChild("Humanoid")
		sound:Play()
		game.Debris:AddItem(sound,2)
		local punchParticle = game.ReplicatedStorage["Particle"].Attachment:Clone()
		punchParticle.Parent = hit.Parent:FindFirstChild("HumanoidRootPart")
		for i, v in pairs(punchParticle:GetChildren()) do
			if v:IsA("ParticleEmitter") then
				v:Emit(30)
				game.Debris:AddItem(punchParticle,0.4)
			end
		end
	end)

	game.Debris:AddItem(hitbox, linger)
end

hitboxEvent.OnServerEvent:Connect(function(plr, size, offset, damage, linger)
	newHitbox(plr.Character, size, offset, damage, linger)
end)
1 Like

Try hrp:ApplyImpulse(). Add a vector3 value inside the brackets to specify the knock back

Isnt applyimpulse only client sided

No it depends on network ownership.

Linear velocity instances automatically replicate to client to it may be easier.

Smoothness is a different story and problem you may need custom client side effects to hide the lag (testing required).

Could u just fire all clients and add linear velocity locally

Ive never tested this but i was just wondering lol

1 Like

guys uh i got the knockback script, i just found out that the guy who made a youtube tutorial for the punch also made a tutorial for knockback, now i just need to know HOW TO FIX ANIMATIONCLIPPROVIDER

Would you be able to provide with a link? I really need a working smooth kb script/ tutorial.