i know setpartcollisiongrup is deprecated but i dont know how to use the new one what i need to change ?
local module = {}
local Players = game:GetService("Players")
local PhysicsService = game:GetService("PhysicsService")
function module:Setup(char)
assert(
Players:GetPlayerFromCharacter(char) == nil,
"Setting up ragdoll on player characters is already done automatically"
)
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")
--for _, v: BasePart in ipairs(char:GetDescendants()) do
-- if v:IsA("BasePart") and v:IsDescendantOf(workspace) and not v.Anchored then
-- v:SetNetworkOwner(nil)
-- end
--end
-- Setup ragdoll
local clones = {}
for i, v in pairs(script.Parent.RagdollParts:GetChildren()) do
clones[v.Name] = v:Clone()
end
for i, v in pairs(clones) do
if v:IsA("Attachment") then
v.Parent = char[v:GetAttribute("Parent")]
elseif v:IsA("BallSocketConstraint") then
v.Parent = char.Torso
v.Attachment0 = clones[v:GetAttribute("0")]
v.Attachment1 = clones[v:GetAttribute("1")]
else
v.Part0 = char.HumanoidRootPart
v.Part1 = char.Torso
v.Parent = char.HumanoidRootPart
end
end
end
function module:Ragdoll(char)
local hrp = char.HumanoidRootPart
local humanoid = char.Humanoid
local weld = hrp.RagdollWeld
local sfx = game.ReplicatedStorage.Sounds.Ragdoll:Clone()
sfx.Parent = hrp
sfx:Play()
game.Debris:AddItem(sfx, 1)
weld.Enabled = true
hrp.CanCollide = false
humanoid.AutoRotate = false
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
for i, v in pairs(char:GetDescendants()) do
if v:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(v, "Ragdoll")
elseif v:IsA("Motor6D") then
v.Enabled = false
elseif v:IsA("BallSocketConstraint") then
v.Enabled = true
end
end
hrp:ApplyAngularImpulse(Vector3.new(-90, 0, 0))
end
function module:Unragdoll(char)
local hrp = char.HumanoidRootPart
local humanoid = char.Humanoid
local weld = hrp.RagdollWeld
weld.Enabled = false
hrp.CanCollide = true
humanoid.AutoRotate = true
humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
for i, v in pairs(char:GetDescendants()) do
if v:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(v, "Default")
elseif v:IsA("Motor6D") then
v.Enabled = true
elseif v:IsA("BallSocketConstraint") then
v.Enabled = false
end
end
end
return module