I made a local script to do a ragdoll script. But when you get killed it makes your character in the same position but you can't move it or remove it. Here's the local script tell me how to make it disappear after a while or help me make it work.
local t = script.Parent.Torso
local n = {"Right Arm" ,"Left Arm" ,"Right Leg" ,"Left Leg" }
local rel = {CFrame.new(1.5, 0, 0) ,CFrame.new(-1.5, 0, 0) ,CFrame.new(0.5, -2, 0) ,CFrame.new(-0.5, -2, 0) }
local C0 = {CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0),CFrame.new(-1.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0),CFrame.new(0.5, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0),CFrame.new(-0.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)}
local C1 = {CFrame.new(-0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0) ,CFrame.new(0, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0) ,CFrame.new(0, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0) ,CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0) }
function weightPart(part)
local p = Instance.new("Part")
p.FormFactor = "Custom"
p.Size = Vector3.new(0.4,0.4,0.4)
p.Parent = script.Parent
p.Transparency = 1
p.CFrame = part.CFrame*CFrame.new(0,-0.5,0)
local w = Instance.new("Weld")
w.Part0 = part
w.Part1 = p
w.C0 = CFrame.new(0,-0.5,0)
w.Parent = p
end
script.Parent:WaitForChild("Humanoid")
script.Parent.Humanoid.Died:connect(function()
local tCfr = script.Parent.Torso.CFrame
script.Parent:BreakJoints()
if script.Parent.Humanoid:FindFirstChild("Cop")~=nil then
local g = game.ReplicatedStorage.GunDrop:Clone()
g.Position = script.Parent.Torso.Position
g.Parent = workspace.Map
end
local m = Instance.new("Model")
m.Parent = workspace
for i,p in ipairs(script.Parent:GetChildren()) do
if p.className=="Tool" then
p:Remove()
else
if p.Name~="Humanoid" then
p.Parent = m
if p.className=="Part" then
if p.Velocity.magnitude>50 then
p.Velocity = p.Velocity.Unit*50
end
p.RotVelocity = Vector3.new(0,0,0)
p:BreakJoints()
p.CanCollide = false
end
end
end
end
local hw = Instance.new("Weld")
hw.Part0 = t
hw.Part1 = script.Parent.Head
hw.C0 = CFrame.new(0,1.5,0)
hw.Parent = t
hw = Instance.new("Weld")
hw.Part0 = script.Parent.Head2
hw.Part1 = script.Parent.Head
hw.Parent = script.Parent.Head
script.Parent.HumanoidRootPart.Size = Vector3.new(0.2,0.2,0.2)
hw = Instance.new("Weld")
hw.Part0 = script.Parent.Torso
hw.Part1 = script.Parent.HumanoidRootPart
hw.Parent = script.Parent.Torso
--script.Parent.Torso.CFrame = script.Parent.Head.CFrame*CFrame.new(0,-1.5,0)
local h = Instance.new("Humanoid")
h.Name = "Dead"
h.PlatformStand = true
h.MaxHealth = 0
h.Health = 0
h.Parent = script.Parent
for i=1,#n do
local part = script.Parent:FindFirstChild(n[i])
if part~=nil then
part.CFrame = t.CFrame*rel[i]
local g = Instance.new("Glue")
g.Part0 = t
g.Part1 = part
g.C0 = C0[i]
g.C1 = C1[i]
g.Parent = t
g.Name = part.Name
weightPart(part)
end
end
local hs = script.Parent:GetChildren()
for i=1,#hs do
if hs[i].className == "Hat" then
local han = hs[i].Handle
han.Parent = script.Parent
local hW = Instance.new("Weld")
hW.Part0 = script.Parent.Head
hW.Part1 = han
hW.C0 = CFrame.new(0, 0.5, 0) * hs[i].AttachmentPoint:inverse()
hW.Parent = han
end
end
t.ChildRemoved:connect(function(c)
print("removed:",c)
for i=1,#n do
if c.Name==n[i] and script.Parent:FindFirstChild(n[i])~=nil then
local part = script.Parent[n[i]]
for _,p in ipairs(script.Parent:GetChildren()) do
if p.className=="Part" then
p.Velocity = Vector3.new(0,0,0)
p.RotVelocity = Vector3.new(0,0,0)
p.Anchored = true
end
end
if part~=nil then
print("attaching part:",part)
part.CFrame = t.CFrame*rel[i]
local g = Instance.new("Glue")
g.Part0 = t
g.Part1 = part
g.C0 = C0[i]
g.C1 = C1[i]
g.Parent = t
g.Name = part.Name
end
end
end
end)
local runServ = game:GetService("RunService")
while game.Players.LocalPlayer.Character==nil or game.Players.LocalPlayer.Character:FindFirstChild("Head")==nil do
workspace.CurrentCamera.CoordinateFrame = m.Head.CFrame
workspace.CurrentCamera.Focus = m.Head.CFrame*CFrame.new(0,0,-1)
runServ.RenderStepped:wait()
end
end)

2 comments
Is this a localscript?
Yes @Awesomespyhacker12