Currently in need of help with editing this script so that it deletes the cloned ragdoll after 10 seconds
local humanoid = script.Parent:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(script.Parent)
local ColliderList = {};
local isInMurder = true;
wait();
local DEBUG = false;
function waitFor( directory, name )
while ( directory == nil or (name ~= nil and directory:FindFirstChild(name) == nil) ) do
wait(0.1);
end
if ( name == nil ) then
return directory;
else
return directory:FindFirstChild(name);
end
end
function setNetworkOwner(m, plr)
for i, bp in pairs(m:GetChildren()) do
if bp:IsA("BasePart") and bp:CanSetNetworkOwnership() then
bp:SetNetworkOwner(plr)
end
end
end
function getCharacter()
return script.Parent;
end
function getPlayer()
return game.Players:GetPlayerFromCharacter(getCharacter());
end
function getHumanoid()
return waitFor( getCharacter(), "Humanoid" );
end
function getNearestPlayer( position )
local Players = game.Players:GetChildren();
local dist = math.huge;
local ret = nil;
for i=1,#Players do
local Player = Players[i];
local Character = Player.Character;
if ( Character ~= nil ) then
local Root = Character:FindFirstChild("HumanoidRootPart");
if ( Root ~= nil ) then
local t = (position - Root.Position).magnitude;
if ( t < dist ) then
dist = t;
ret = Player;
end
end
end
end
return ret;
end
function check(char)
for i, v in pairs(char:GetChildren()) do
if v:IsA("LocalScript") then
v:Destroy()
end
end
if char.Humanoid.RigType == Enum.HumanoidRigType.R15 then
return "R15"
else
return "R6"
end
end
function ragdoll(char, rig)
if rig == "R6" then
local Character = char
for i, v in pairs(char:GetChildren()) do
if v:IsA("Motor6D") or v:IsA("LocalScript") then
v:Destroy()
end
end
char.Humanoid.Health = 0
local Torso = char:FindFirstChild("Torso")
if Torso then
local Head = Character:FindFirstChild("Head")
if Head then
local Neck = Instance.new("Weld")
Neck.Name = "Neck"
Neck.Part0 = Torso
Neck.Part1 = Head
Neck.C0 = CFrame.new(0, 1.5, 0)
Neck.C1 = CFrame.new()
Neck.Parent = Torso
end
local Limb = Character:FindFirstChild("Right Arm")
if Limb then
Limb.CFrame = Torso.CFrame * CFrame.new(1.5, 0, 0)
local Joint = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment", Torso)
local a2 = Instance.new("Attachment", Limb)
Joint.Name = "RightShoulder"
Joint.Attachment0 = a1
Joint.Attachment1 = a2
a1.CFrame = CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
a2.CFrame = CFrame.new(-0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.Parent = Torso
local B = Instance.new("Part")
B.TopSurface = 0
B.BottomSurface = 0
B.formFactor = "Symmetric"
B.Size = Vector3.new(1, 1, 1)
B.Transparency = 1
B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
B.Parent = Character
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, -0.5, 0)
W.Parent = Limb
end
local Limb = Character:FindFirstChild("Left Arm")
if Limb then
Limb.CFrame = Torso.CFrame * CFrame.new(-1.5, 0, 0)
local Joint = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment", Torso)
local a2 = Instance.new("Attachment", Limb)
Joint.Name = "LeftShoulder"
Joint.Attachment0 = a1
Joint.Attachment1 = a2
a1.CFrame = CFrame.new(-1.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
a2.CFrame = CFrame.new(0, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.Parent = Torso
local B = Instance.new("Part")
B.TopSurface = 0
B.BottomSurface = 0
B.formFactor = "Symmetric"
B.Size = Vector3.new(1, 1, 1)
B.Transparency = 1
B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
B.Parent = Character
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, -0.5, 0)
W.Parent = Limb
end
local Limb = Character:FindFirstChild("Right Leg")
if Limb then
Limb.CFrame = Torso.CFrame * CFrame.new(0.5, -2, 0)
local Joint = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment", Torso)
local a2 = Instance.new("Attachment", Limb)
Joint.Name = "RightHip"
Joint.Attachment0 = a1
Joint.Attachment1 = a2
a1.CFrame = CFrame.new(0.5, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
a2.CFrame = CFrame.new(0, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.Parent = Torso
local B = Instance.new("Part")
B.TopSurface = 0
B.BottomSurface = 0
B.formFactor = "Symmetric"
B.Size = Vector3.new(1, 1, 1)
B.Transparency = 1
B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
B.Parent = Character
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, -0.5, 0)
W.Parent = Limb
end
local Limb = Character:FindFirstChild("Left Leg")
if Limb then
Limb.CFrame = Torso.CFrame * CFrame.new(-0.5, -2, 0)
local Joint = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment", Torso)
local a2 = Instance.new("Attachment", Limb)
Joint.Name = "LeftHip"
Joint.Attachment0 = a1
Joint.Attachment1 = a2
a1.CFrame = CFrame.new(-0.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
a2.CFrame = CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.Parent = Torso
local B = Instance.new("Part")
B.TopSurface = 0
B.BottomSurface = 0
B.formFactor = "Symmetric"
B.Size = Vector3.new(1, 1, 1)
B.Transparency = 1
B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
B.Parent = Character
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, -0.5, 0)
W.Parent = Limb
end
--[
local Bar = Instance.new("Part")
Bar.TopSurface = 0
Bar.BottomSurface = 0
Bar.formFactor = "Symmetric"
Bar.Size = Vector3.new(1, 1, 1)
Bar.Transparency = 1
Bar.CFrame = Torso.CFrame * CFrame.new(0, 0.5, 0)
Bar.Parent = Character
local Weld = Instance.new("Weld")
Weld.Part0 = Torso
Weld.Part1 = Bar
Weld.C0 = CFrame.new(0, 0.5, 0)
Weld.Parent = Torso
--]]
end
if char:FindFirstChild("HumanoidRootPart") ~= nil then char.HumanoidRootPart.Parent = nil end
char.Humanoid.PlatformStand = true
elseif rig == "R15" then
--[[char.Humanoid.Parent = nil
local newhum = Instance.new("Humanoid")
newhum.Parent = char
newhum.Health = 0
newhum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None]]
local RootLimbData = {
{
["WeldTo"] = "LowerTorso",
["WeldRoot"] = "HumanoidRootPart",
["AttachmentName"] = "Root",
["NeedsCollider"] = false,
["UpperAngle"] = 10
},
{
["WeldTo"] = "UpperTorso",
["WeldRoot"] = "LowerTorso",
["AttachmentName"] = "Waist",
["ColliderOffset"] = CFrame.new(0, 0.5, 0),
["UpperAngle"] = 0
},
{
["WeldTo"] = "Head",
["WeldRoot"] = "UpperTorso",
["AttachmentName"] = "Neck",
["ColliderOffset"] = CFrame.new(),
["UpperAngle"] = 20
},
{
["WeldTo"] = "LeftUpperLeg",
["WeldRoot"] = "LowerTorso",
["AttachmentName"] = "LeftHip",
["ColliderOffset"] = CFrame.new(0, -0.5, 0)
},
{
["WeldTo"] = "RightUpperLeg",
["WeldRoot"] = "LowerTorso",
["AttachmentName"] = "RightHip",
["ColliderOffset"] = CFrame.new(0, -0.5, 0)
},
{
["WeldTo"] = "RightLowerLeg",
["WeldRoot"] = "RightUpperLeg",
["AttachmentName"] = "RightKnee",
["ColliderOffset"] = CFrame.new(0, -0.5, 0)
},
{
["WeldTo"] = "LeftLowerLeg",
["WeldRoot"] = "LeftUpperLeg",
["AttachmentName"] = "LeftKnee",
["ColliderOffset"] = CFrame.new(-0.05, -0.5, 0)
},
{
["WeldTo"] = "RightUpperArm",
["WeldRoot"] = "UpperTorso",
["AttachmentName"] = "RightShoulder",
["ColliderOffset"] = CFrame.new(0.05, 0.45, 0.15),
},
{
["WeldTo"] = "LeftUpperArm",
["WeldRoot"] = "UpperTorso",
["AttachmentName"] = "LeftShoulder",
["ColliderOffset"] = CFrame.new(0, 0.45, 0.15),
},
{
["WeldTo"] = "LeftLowerArm",
["WeldRoot"] = "LeftUpperArm",
["AttachmentName"] = "LeftElbow",
["ColliderOffset"] = CFrame.new(0, 0.125, 0),
["UpperAngle"] = 10
},
{
["WeldTo"] = "RightLowerArm",
["WeldRoot"] = "RightUpperArm",
["AttachmentName"] = "RightElbow",
["ColliderOffset"] = CFrame.new(0, 0.125, 0),
["UpperAngle"] = 10
},
{
["WeldTo"] = "RightHand",
["WeldRoot"] = "RightLowerArm",
["AttachmentName"] = "RightWrist",
["ColliderOffset"] = CFrame.new(0, 0.125, 0),
["UpperAngle"] = 0
},
{
["WeldTo"] = "LeftHand",
["WeldRoot"] = "LeftLowerArm",
["AttachmentName"] = "LeftWrist",
["ColliderOffset"] = CFrame.new(0, 0.125, 0),
["UpperAngle"] = 0
},
{
["WeldTo"] = "LeftFoot",
["WeldRoot"] = "LeftLowerLeg",
["AttachmentName"] = "LeftAnkle",
["NeedsCollider"] = false,
["UpperAngle"] = 0
},
{
["WeldTo"] = "RightFoot",
["WeldRoot"] = "RightLowerLeg",
["AttachmentName"] = "RightAnkle",
["NeedsCollider"] = false,
["UpperAngle"] = 0
},
}
local RootPart = nil;
local MotorList = {};
local GlueList = {};
local ColliderList = {};
print("Ragdolling");
local Character = char
local Humanoid = char.Humanoid
local HumanoidRoot = script.Parent:FindFirstChild("HumanoidRootPart");
if ( HumanoidRoot == nil ) then
print("Cannot create ragdoll");
return;
end
local Position = script.Parent.HumanoidRootPart.Position;
Humanoid.PlatformStand = true;
-- Handle death specific ragdoll. Will Clone you, then destroy you.
local RagDollModel = Character;
-- Reglue The Character
for i=1,#RootLimbData do
local limbData = RootLimbData[i];
local partName = limbData["WeldTo"];
local weldName = limbData["WeldRoot"];
local PartTo = RagDollModel:FindFirstChild(partName);
local WeldTo = RagDollModel:FindFirstChild(weldName);
if ( PartTo ~= nil and WeldTo ~= nil ) then
if ( RagDollModel ~= nil ) then
PartTo.Parent = RagDollModel;
end
-- Create New Constraint
local UpperAngle = limbData["UpperAngle"];
local Joint = Instance.new("BallSocketConstraint");
if ( (UpperAngle ~= nil and UpperAngle == 0) or (partName == "Head") ) then
Joint = Instance.new("HingeConstraint");
Joint.UpperAngle = 0;
Joint.LowerAngle = 0;
end
Joint.Name = limbData["AttachmentName"];
Joint.LimitsEnabled = true;
Joint.Attachment0 = PartTo:FindFirstChild(Joint.Name .. "RigAttachment");
Joint.Attachment1 = WeldTo:FindFirstChild(Joint.Name .. "RigAttachment");
Joint.Parent = PartTo;
GlueList[#GlueList+1] = Joint;
if ( UpperAngle ~= nil ) then
Joint.UpperAngle = UpperAngle;
end
-- Destroy the motor attaching it
local Motor = PartTo:FindFirstChildOfClass("Motor6D");
if ( Motor ~= nil ) then
if ( Humanoid.Health <= 0 ) then
Motor:Destroy();
else
MotorList[#MotorList+1] = { PartTo, Motor };
Motor.Parent = nil;
end
end
-- Create Collider
local needsCollider = limbData["NeedsCollider"];
if ( needsCollider == nil ) then
needsCollider = true;
end
if ( needsCollider ) then
local B = Instance.new("Part");
B.CanCollide = true;
B.TopSurface = 0;
B.BottomSurface = 0;
B.formFactor = "Symmetric";
B.Size = Vector3.new(0.7, 0.7, 0.7);
B.Transparency = 1;
B.BrickColor = BrickColor.Red();
B.Parent = RagDollModel;
local W = Instance.new("Weld");
W.Part0 = PartTo;
W.Part1 = B;
W.C0 = limbData["ColliderOffset"];
W.Parent = PartTo;
ColliderList[#ColliderList+1] = B;
end
end
end
-- Destroy Root Part
local root = Character:FindFirstChild("HumanoidRootPart");
if ( root ~= nil ) then
RootPart = root;
if ( Humanoid.Health <= 0 ) then
RootPart:Destroy();
else
RootPart.Parent = nil;
end
end
-- Delete all my parts if we made a new ragdoll
print("Deleting character");
humanoid.Parent.Parent = nil
-- Set network owner
setNetworkOwner(RagDollModel, getPlayer())
-- Give player physics
local PlayerPhysics = getNearestPlayer( Position );
if PlayerPhysics == nil then
PlayerPhysics = getPlayer();
end
local Children = RagDollModel:GetChildren();
for i=1,#Children do
local Child = Children[i];
if ( Child:IsA("BasePart") ) then
Child:SetNetworkOwner(PlayerPhysics);
end
end
end
game.Debris:AddItem(char, 1200)
end
humanoid.Died:Connect(function()
script.Parent.Archivable = true
local charcl = script.Parent:Clone()
script.Parent.Archivable = false
charcl.Parent = workspace
charcl.Humanoid.PlatformStand = true
charcl.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
--charcl.Humanoid.AutoRotate = false
if isInMurder then
if script.Parent:FindFirstChild("Cop") ~= nil then
local g = game.ServerStorage.GunDrop:Clone()
g.Parent = workspace.MapHolder
g.Position = charcl.HumanoidRootPart.Position
end
end
local rigtype = check(charcl)
ragdoll(charcl, rigtype)
if getPlayer() ~= nil then
local cam = script.cam:Clone()
cam.Parent = game.Players:GetPlayerFromCharacter(script.Parent).PlayerGui
cam.focus.Value = charcl.Head
cam.Disabled = false
local char = script.Parent
script.Parent = game.ReplicatedStorage
char:Destroy()
wait(game.Players.RespawnTime)
player:LoadCharacter()
script:Destroy()
else
local char = script.Parent
char:Destroy()
end
end)