So I have a ragdoll script for a game that I’m making. The ragdoll script I use interacts perfectly with an NPC, but with a player it makes them fly around and get stuck in the floor.
Ragdoll toward an NPC:
Ragdoll toward a player:
My ragdoll script:
local ragdoll = {}
function ragdoll.Start(character)
if character.Name == (nil or "Workspace") then return end
if character.Values.Ragdoll.Value == true then return end
local realrARM = character["Right Arm"]
local reallARM = character["Left Arm"]
local realrLEG = character["Right Leg"]
local reallLEG = character["Left Leg"]
character.Values.Ragdoll.Value = true
character.Values.CanBeAttacked.Value = false
character["Right Arm"].CanCollide = true
character["Left Arm"].CanCollide = true
character["Right Leg"].CanCollide = true
character["Left Leg"].CanCollide = true
local rARM = character["Right Arm"]:Clone()
rARM.CollisionGroup = "Ragdoll"
local lARM = character["Left Arm"]:Clone()
lARM.CollisionGroup = "Ragdoll"
local rLEG = character["Right Leg"]:Clone()
rLEG.CollisionGroup = "Ragdoll"
local lLEG = character["Left Leg"]:Clone()
lLEG.CollisionGroup = "Ragdoll"
--[[character["Right Arm"].CanCollide = false
character["Left Arm"].CanCollide = false
character["Right Leg"].CanCollide = false
character["Left Leg"].CanCollide = false]]
--[[rARM.Name = "Ragdoll-RA"
lARM.Name = "Ragdoll-LA"
rLEG.Name = "Ragdoll-RL"
lLEG.Name = "Ragdoll-LL"]]
rARM.Parent = character
lARM.Parent = character
rLEG.Parent = character
lLEG.Parent = character
rARM.CFrame = character["Right Arm"].CFrame
lARM.CFrame = character["Left Arm"].CFrame
rLEG.CFrame = character["Right Leg"].CFrame
lLEG.CFrame = character["Left Leg"].CFrame
character.Torso["Right Shoulder"].Part1 = rARM
character.Torso["Left Shoulder"].Part1 = lARM
character.Torso["Right Hip"].Part1 = rLEG
character.Torso["Left Hip"].Part1 = lLEG
character["Right Arm"].Anchored = true
character["Left Arm"].Anchored = true
character["Right Leg"].Anchored = true
character["Left Leg"].Anchored = true
character["Right Arm"].Transparency = 1
character["Left Arm"].Transparency = 1
character["Right Leg"].Transparency = 1
character["Left Leg"].Transparency = 1
character["Right Arm"].CastShadow = false
character["Left Arm"].CastShadow = false
character["Right Leg"].CastShadow = false
character["Left Leg"].CastShadow = false
character["Right Arm"].CanTouch = false
character["Left Arm"].CanTouch = false
character["Right Leg"].CanTouch = false
character["Left Leg"].CanTouch = false
rARM.Anchored = false
lARM.Anchored = false
rLEG.Anchored = false
lLEG.Anchored = false
for i, joint in pairs(character:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a0 = Instance.new("Attachment")
local a1 = Instance.new("Attachment")
a0.Parent = joint.Part0
a1.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a0
socket.Attachment1 = a1
a0.CFrame = joint.C0
a1.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
joint.Enabled = false
end
end
character.Humanoid.WalkSpeed = 0
character.Humanoid.JumpPower = 0
character.Humanoid.PlatformStand = true
character.Humanoid.AutoRotate = false
character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
local collisions = coroutine.create(function()
while character and character.Values.Ragdoll.Value do
rARM.CanCollide = true
realrARM.CanCollide = false
lARM.CanCollide = true
reallARM.CanCollide = false
rLEG.CanCollide = true
realrLEG.CanCollide = false
lLEG.CanCollide = true
reallLEG.CanCollide = false
wait(0.1)
end
end)
coroutine.resume(collisions)
character.Humanoid.Died:Connect(function()
wait(0.5)
realrARM:Destroy()
reallARM:Destroy()
realrLEG:Destroy()
reallLEG:Destroy()
end)
end
function ragdoll.Stop(character)
if character.Humanoid:GetState() == Enum.HumanoidStateType.Dead then return end
--character.HumanoidRootPart.Anchored = true
--wait()
--character.HumanoidRootPart.Anchored = false
character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
local hrp = character:FindFirstChild("HumanoidRootPart")
local hum = character:FindFirstChild("Humanoid")
for i,part in pairs(character:GetChildren()) do
if part:IsA("Part") then
if part.CollisionGroup == "Ragdoll" then
part:Destroy()
end
end
end
character["Right Arm"].Anchored = false
character["Left Arm"].Anchored = false
character["Right Leg"].Anchored = false
character["Left Leg"].Anchored = false
character["Right Arm"].CanTouch = true
character["Left Arm"].CanTouch = true
character["Right Leg"].CanTouch = true
character["Left Leg"].CanTouch = true
character.Torso["Right Shoulder"].Part1 = character["Right Arm"]
character.Torso["Left Shoulder"].Part1 = character["Left Arm"]
character.Torso["Right Hip"].Part1 = character["Right Leg"]
character.Torso["Left Hip"].Part1 = character["Left Leg"]
character["Right Arm"].Transparency = 0
character["Left Arm"].Transparency = 0
character["Right Leg"].Transparency = 0
character["Left Leg"].Transparency = 0
character["Right Arm"].CastShadow = true
character["Left Arm"].CastShadow = true
character["Right Leg"].CastShadow = true
character["Left Leg"].CastShadow = true
for i, joint in pairs(character:GetDescendants()) do
if joint:IsA("BallSocketConstraint") then
joint:Destroy()
end
if joint:IsA("Motor6D") then
joint.Enabled = true
end
end
character.Values.Ragdoll.Value = false
character.Values.CanBeAttacked.Value = true
hum.WalkSpeed = 22
hum.JumpPower = 42
hum.AutoRotate = true
hum.PlatformStand = false
character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
hum.Sit = true
wait(0.1)
hum.Sit = false
end
return ragdoll