So, I have a problem, my ragdoll knockback script works for only NPCS and not players I tried setting the network ownership, Btw I use smooth r6 ragdoll module (Plug-Play): – hit char module `local Hit = {}
local rocks = require(game.ReplicatedStorage.Rocks)
local ragdoll = require(game.ServerScriptService.R6Ragdoll.ModuleScript)
function Hit.hitChar(hum,dmg,hitref,mforce,knockbackPos,dr,ragdolldr)
local char = hum.Parent
local humanoid = char.Humanoid
--print(humanoid.Health)
if humanoid.Health <= 0 then return end
if char:GetAttribute("Ragdolled") then return end
if hitref == "hit" then
if hum.Health > 0 then
humanoid:TakeDamage(dmg)
local a0 = Instance.new("Attachment", char.HumanoidRootPart)
local a1 = Instance.new("Attachment", char.HumanoidRootPart)
local lv = Instance.new("LinearVelocity")
lv.Parent = char.PrimaryPart
lv.VectorVelocity = knockbackPos
lv.MaxForce = mforce
lv.Attachment0 = a0
lv.Attachment1 = a1
task.delay(dr, function()
lv:Destroy()
end)
else
return
end
elseif hitref == "knockback" then
if hum.Health > 0 then
local humanoid: BasePart = hum.Parent:FindFirstChildOfClass("Humanoid")
char.HumanoidRootPart:SetNetworkOwner(nil)
hum:ChangeState(Enum.HumanoidStateType.Ragdoll)
hum:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
ragdoll:Ragdoll(char)
humanoid.RequiresNeck = false
task.spawn(function()
task.wait(ragdolldr)
hum:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
char.HumanoidRootPart:SetNetworkOwner(game.Players:FindFirstChild(char.Name))
ragdoll:Unragdoll(char)
humanoid.RequiresNeck = true
end)
task.spawn(function()
local a0 = Instance.new("Attachment", char.HumanoidRootPart)
local a1 = Instance.new("Attachment", char.HumanoidRootPart)
local lv = Instance.new("LinearVelocity")
lv.Parent = char.PrimaryPart
lv.VectorVelocity = knockbackPos
lv.MaxForce = mforce
lv.Attachment0 = a0
lv.Attachment1 = a1
task.wait(dr)
lv:Destroy()
end)
else
print("Cant ragdoll because health is greather then 0!")
end
end
end
return Hit-- r6 ragdoll module :
local module = {}
local Players = game:GetService(“Players”)
local PhysicsService = game:GetService(“PhysicsService”)
local ragParts = script.Parent.RagdollParts:GetChildren()
function module:Setup(char: Model)
local humanoid = char:FindFirstChild(“Humanoid”)
assert(humanoid, “Can only set-up ragdoll on R6 humanoid rigs”)
assert(humanoid.RigType == Enum.HumanoidRigType.R6, “Can only set-up ragdoll on R6 humanoid rigs”)
assert(humanoid.RootPart ~= nil, “No RootPart was found in the provided rig”)
assert(char:FindFirstChild(“HumanoidRootPart”), “No HumanoidRootPart was found in the provided rig”)
-- Ensure network ownership for player characters
for _, v: BasePart in ipairs(char:GetDescendants()) do
if v:IsA("BasePart") then
v:SetNetworkOwner(nil)
end
end
-- Setup ragdoll
char.Head.Size = Vector3.new(1, 1, 1)
humanoid.BreakJointsOnDeath = false
humanoid.RequiresNeck = false
local clones = {}
for _, v in ipairs(ragParts) do
clones[v.Name] = v:Clone()
end
local folder1 = Instance.new("Folder")
folder1.Name = "RagdollConstraints"
for _, v in pairs(clones) do
if v:IsA("Attachment") then
v.Parent = char[v:GetAttribute("Parent")]
elseif v:IsA("BallSocketConstraint") then
v.Attachment0 = clones[v:GetAttribute("0")]
v.Attachment1 = clones[v:GetAttribute("1")]
v.Parent = folder1
end
end
folder1.Parent = char
local folder2 = Instance.new("Folder")
folder2.Name = "Motors"
for _, v in ipairs(char.Torso:GetChildren()) do
if v:IsA("Motor6D") then
local value = Instance.new("ObjectValue")
value.Value = v
value.Parent = folder2
end
end
folder2.Parent = folder1
-- Ragdoll trigger
local trigger = Instance.new("BoolValue")
trigger.Name = "RagdollTrigger"
trigger.Parent = char
trigger.Changed:Connect(function(bool)
if bool then
module:Ragdoll(char)
else
module:Unragdoll(char)
end
end)
end
function module:Ragdoll(char: Model)
print(“Ragdolled”, char.Name)
char.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
char:SetAttribute(“Ragdolled”, true)
char.Humanoid.AutoRotate = false
for _, v in ipairs(char.RagdollConstraints.Motors:GetChildren()) do
v.Value.Enabled = false
end
for _, v in ipairs(char:GetChildren()) do
if v:IsA("BasePart") then
v.CollisionGroup = "Ragdoll"
end
end
char.HumanoidRootPart:ApplyAngularImpulse(Vector3.new(-90, 0, 0))
end
function module:Unragdoll(char: Model)
print(“UnRagdolled”, char.Name)
char.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
char:SetAttribute(“Ragdolled”, false)
for _, v in ipairs(char.RagdollConstraints.Motors:GetChildren()) do
v.Value.Enabled = true
end
for _, v in ipairs(char:GetChildren()) do
if v:IsA("BasePart") then
v.CollisionGroup = "Default"
end
end
char.Humanoid.AutoRotate = true
end
return module
`