Any ideas how i can apply a knockback while ragdolled?

Hello, im trying to do a knockback/pushback when the player is ragdolled on the 4th hit, but im not sure if im using the wrong method to push the player back or not, right now im using HumanoidRootPart.Velocity = direction * force
here is what it looks like in game
https://gyazo.com/9a6b7222e7d7fa3a4e1d54096ebb5a42
and this is the script part of the knockback

local function HandleHit(hit)
		local enemyCharacter = hit.Parent
		if enemyCharacter and enemyCharacter ~= character then
			local enemyHumanoid = enemyCharacter:FindFirstChild("Humanoid")
			local ragdollTrigger = enemyCharacter:FindFirstChild("RagdollTrigger")
			local enemyRootPart = enemyCharacter:FindFirstChild("HumanoidRootPart")
			local playerRootPart = character:FindFirstChild("HumanoidRootPart")

			if enemyHumanoid and enemyRootPart and playerRootPart then
				-- Prevent multiple hits on the same enemy using a debounce
				if hitDebounce[enemyCharacter] then return end
				hitDebounce[enemyCharacter] = true

				-- Skip if the enemy is already ragdolled
				if ragdollTrigger and ragdollTrigger.Value then
					return
				end

				-- Apply damage
				enemyHumanoid:TakeDamage(DAMAGE)

				-- Apply knockback and ragdoll only on the 4th swing
				if swingIndex == 4 then
					-- Calculate knockback direction
					local direction = (enemyRootPart.Position - playerRootPart.Position).Unit
					enemyRootPart.Velocity = direction * KNOCKBACK_FORCE

					-- Apply ragdoll
					if ragdollTrigger then
						ragdollTrigger.Value = true

						-- Reset ragdoll after a short delay
						task.delay(1, function()
							ragdollTrigger.Value = false
						end)
					end
				end

				-- Clear the debounce after HIT_DEBOUNCE_TIME
				task.delay(HIT_DEBOUNCE_TIME, function()
					hitDebounce[enemyCharacter] = nil
				end)
			end
		end
	end

You could use ApplyImpulse()

enemyRootPart:ApplyImpulse(direction * KNOCKBACK_FORCE)

It adds onto the current velocity instead of replacing it, which is more realistic if you, for example applied knockback while standing on a moving vehicle.

i tried that just now, and nothing has changed, the player still flops on the floor without being pushed back, i tried to increase the knockback force too

i just sorted it myself, i added a velocity to the enemy manually when the 4th hit is registered

if swingIndex == 4 then
					-- Calculate knockback direction
					local direction = (enemyRootPart.Position - playerRootPart.Position).Unit

					-- Ensure knockback is applied regardless of player death
					local bodyVelocity = Instance.new("BodyVelocity")
					bodyVelocity.Velocity = direction * KNOCKBACK_FORCE
					bodyVelocity.MaxForce = Vector3.new(1e6, 1e8, 1e6) -- Strong enough to push the player
					bodyVelocity.P = 1250 -- Adjust this for fine-tuning knockback responsiveness
					bodyVelocity.Parent = enemyRootPart

					-- Remove the BodyVelocity after a short delay
					task.delay(0.2, function()
						bodyVelocity:Destroy()
					end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.