Pushing tool not applying impulse

I am trying to make a tool that lets you push others with ragdoll.

The problem is that it doesn’t push the player, only ragdolls it.

I have tried to change the order of operations.

Here is the local script that is in the tool:

local tool = script.Parent
local player = game.Players.LocalPlayer
local COOLDOWN = 0.7
local ANIMATION_ID = "rbxassetid://84377870330120"

local canFire = true
local remote = tool:WaitForChild("PushEvent")

tool.Activated:Connect(function()
	if not canFire then return end
	canFire = false

	local character = player.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		local animator = humanoid:FindFirstChild("Animator")
		if animator then
			local anim = Instance.new("Animation")
			anim.AnimationId = ANIMATION_ID
			local track = animator:LoadAnimation(anim)
			track.Priority = Enum.AnimationPriority.Action4
			track:Play()
		end
	end

	task.delay(0.25, function()
		remote:FireServer()
	end)

	task.wait(COOLDOWN)
	canFire = true
end)

Here is the serverscript:

local Debris = game:GetService("Debris")
local tool = script.Parent

local RANGE = 2
local WIDTH, HEIGHT = 6, 4
local DELTA_V = 120
local RAGDOLL_TIME = 2

local remote = tool:WaitForChild("PushEvent")

local function ragdoll(character)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid.PlatformStand = true
	end

	local motors = {}
	for _, joint in pairs(character:GetDescendants()) do
		if joint:IsA("Motor6D") then
			table.insert(motors, {Motor=joint, Parent=joint.Parent, C0=joint.C0, C1=joint.C1})
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
		end
	end
	return motors
end

local function standUp(character, motors)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid.PlatformStand = false
	end

	for _, data in ipairs(motors) do
		if data.Parent and character.Parent then
			local newMotor = Instance.new("Motor6D")
			newMotor.Part0 = data.Motor.Part0
			newMotor.Part1 = data.Motor.Part1
			newMotor.C0 = data.C0
			newMotor.C1 = data.C1
			newMotor.Parent = data.Parent
		end
	end
end

local function push(character)
	local hrp = character:FindFirstChild("HumanoidRootPart")
	if not hrp then return end

	local size = Vector3.new(WIDTH, HEIGHT, RANGE)
	local cf = hrp.CFrame * CFrame.new(0, 0, -(RANGE/2 + 2))
	local partsInBox = workspace:GetPartBoundsInBox(cf, size)
	local alreadyHit = {}

	local hitboxVisual = Instance.new("Part")
	hitboxVisual.Size = size
	hitboxVisual.CFrame = cf
	hitboxVisual.Anchored = true
	hitboxVisual.CanCollide = false
	hitboxVisual.CanQuery = false
	hitboxVisual.CanTouch = false
	hitboxVisual.Transparency = 0.5
	hitboxVisual.Color = Color3.fromRGB(255, 0, 0)
	hitboxVisual.Parent = workspace
	Debris:AddItem(hitboxVisual, 0.15)

	for _, part in ipairs(partsInBox) do
		local otherChar = part:FindFirstAncestorOfClass("Model")
		local hum = otherChar and otherChar:FindFirstChildOfClass("Humanoid")
		local otherHRP = otherChar and otherChar:FindFirstChild("HumanoidRootPart")
		if not (hum and otherHRP) then continue end
		if otherChar == character then continue end
		if alreadyHit[otherChar] then continue end
		alreadyHit[otherChar] = true

		local targetChar = otherChar
		local targetHRP = otherHRP
		local myHRP = hrp

		task.spawn(function()
			if not (targetChar and targetHRP and myHRP) then return end

			local motors = ragdoll(targetChar)
			task.wait(0.05)

			local dir = targetHRP.Position - myHRP.Position
			dir = Vector3.new(dir.X, 0, dir.Z)
			if dir.Magnitude > 0 then
				dir = dir.Unit
				local impulse = dir * math.max(targetHRP.AssemblyMass * (DELTA_V/2), 30)
				local originalOwner = targetHRP:GetNetworkOwner()
				targetHRP:SetNetworkOwner(nil)
				if targetHRP.ApplyImpulse then
					targetHRP:ApplyImpulse(impulse)
				else
					targetHRP.AssemblyLinearVelocity = impulse
				end
				targetHRP:SetNetworkOwner(originalOwner)
			end

			task.wait(RAGDOLL_TIME)
			if targetChar.Parent then
				standUp(targetChar, motors)
			end
		end)
	end
end

remote.OnServerEvent:Connect(function(player)
	local char = player.Character
	if char then
		push(char)
	end
end)

I was testing your code and noticed that when you push, it’s not moving with enough force, and it’s only throwing forward, which doesn’t really give the impression that it’s being pushed. I’d recommend changing the following:

local DELTA_V = 360
dir = Vector3.new(dir.X, 5, dir.Z)
local impulse = dir * targetHRP.AssemblyMass * DELTA_V

What will determine how far the push goes in this case will be the DELTA_V

After making the following changes, it appears that the push is only working on a dummy with no accessories.

Are you applying the impulse on the server or on the client’s side? Most of the times the reason why velocity isn’t applied is because it’s not the network owner of the part who’s handling the impulse

Edit: I didn’t see that youre changing the network owner but I believe the reason why the impulse isn’t applied is because the script isn’t waiting after the ownership transfer, you’re basically applying the impulse while the network ownership switch is still happening.

Ah I see. I will try this once I’m able to get on my computer.

Edit: I’d like to also note that it didnt work on a dummy with accessories but it did on a dummy with accessories.

It did not work. I implemented the wait for the ownership transfer like this: repeat task.wait() until targetHRP:GetNetworkOwner() == nil

and it’s right after targetHRP:SetNetworkOwner(nil)

Search up previous posts about ‘shove’ or ‘push’ or ‘push back’.
Other posts I’ve seen have solutions that may work for you.

I’m pretty sure it has something to do with the target’s Humanoid physics pushing back. It’s not like you are just pushing a stationary Part. A Humanoid is resisting game physics so it doesn’t yeet off the baseplate every time it gets hit.

I found the solution on my own, thanks to everyone who responded!
The problem was that I was setting network ownership back to the player too quickly, and the physics didn’t have time to simulate the push. So, I placed the network ownership change in the if statement and it’s working now!