NPCs take knockback but player characters don't

hello :slight_smile:
I have a script that uses ApplyImpulse() on a HumanoidRootPart to knockback a character. However, as the title suggests, the ApplyImpulse() only works on NPCs. When I tested the same knockback system on actual player characters, they do not get knockbacked at all. How would I fix this?

-- This is a module
local Module = {}
local RE = game.ReplicatedStorage.Events.Ragdoll
local PS = game:GetService("PhysicsService")

Module.Ragdoll = function(char:Model, timer:number, power:number, direction:Vector3)
	local plr = game.Players:GetPlayerFromCharacter(char)
	if char.Humanoid.Health~=0 and ((char:FindFirstChild'LowerTorso'and char.LowerTorso.Root.Enabled) or (char:FindFirstChild'Torso'and char.Torso.Neck.Enabled)) then
		RE:FireClient(plr,true)
		for _,v in pairs(char:GetDescendants()) do
			if v:IsA'Motor6D'and Module.Check(v.Name)then
				v.Enabled = false
			elseif v:IsA'BallSocketConstraint' then
				v.Enabled = true
			elseif v.Name=="Head"then
				local b = Instance.new("BodyVelocity",char.Head)
				b.Velocity = Vector3.new(math.random(-10,10),0,math.random(-10,10))
				task.spawn(function()
					wait(.1)
					b:Destroy()
				end)
			end
		end
		
		print(power)
		char.HumanoidRootPart:ApplyImpulse(direction * (power * 12))
		char:SetAttribute("Ragdolled", true)
		------------------------------------------------------------------------------------------------
		if timer == nil then
			timer = power / 50
		end
		wait(timer)
		------------------------------------------------------------------------------------------------
		RE:FireClient(plr,false)
		for _,v in pairs(char:GetDescendants()) do
			if v:IsA'Motor6D' then
				v.Enabled = true
			elseif v:IsA'BallSocketConstraint' then
				v.Enabled = false
			end
		end
		char:SetAttribute("Ragdolled", false)
	end
end



Module.Bot = function(bot:Model, timer:number, power:number, direction:Vector3)
	task.spawn(function()
		local H = bot.Humanoid
		bot.HumanoidRootPart:SetNetworkOwner(nil)
		if bot:FindFirstChild'HumanoidRootPart'and H.Health~=0 and (bot:FindFirstChild'Torso' and bot.Torso.Neck.Enabled==true) or (bot:FindFirstChild('LowerTorso') and bot.LowerTorso.Root.Enabled==true) and timer then
			H:SetStateEnabled(Enum.HumanoidStateType.GettingUp,false)
			H:ChangeState(Enum.HumanoidStateType.Ragdoll)
			for _,v in pairs(H:GetPlayingAnimationTracks())do v:Stop(0)end
			bot.Animate.Disabled = true
			
			for _,v in pairs(bot:GetDescendants()) do
				if v:IsA'Motor6D'and Module.Check(v.Name) then
					v.Enabled = false
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = true
				end
			end
			
			bot.HumanoidRootPart:ApplyImpulse(direction * (power * 12))
			
			if timer == nil then
				timer = power / 50
			end
			wait(timer)

			bot.Animate.Disabled = false
			H:SetStateEnabled(Enum.HumanoidStateType.GettingUp,true)
			H:ChangeState(Enum.HumanoidStateType.GettingUp)

			for _,v in pairs(bot:GetDescendants()) do
				if v:IsA'Motor6D' then
					v.Enabled = true
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = false
				end
			end
		end
	end)
end

The script that uses the module gives the same arguments to both functions. No matter what number I changed the power to, the ApplyImpulse() never seemed to activate.

Edit: I realised that the force seems to build up, and it only activates when the character dies.

2 Likes

This is happening because the server doesn’t have physics ownership of the player’s character, what you will have to do is fire a RemoteEvent from the server to the client that got hit and then detect this event on the client and run part of the code there, for example:

RemoteEvent.OnClientEvent:Connect(function(direction, power)
	character.HumanoidRootPart:ApplyImpulse(direction * (power * 12))
end)
2 Likes

I knew that the client had access to the character’s properties, but I didn’t know they had access to the physics of the character (if that makes sense). What if I want to check the force that is being applied on the character? Say, I have an ability that requires checking the velocity of the character, how would I check it if the client does not replicate to the server? Since the client changed applied the impulse, the server wouldnt know.

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