hello
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.