Hey all, I was wondering is there a way to stop an instance repeatedly duplicating itself? This is inside my Ragdoll script, upon NPC death, goes in to Ragdoll however, The two Instances that are duplicating more than once are; Humanoid - Line 144 - 148 AllowPick - Line 150 - 153
They don't duplicate continously, only about 10+ times inside the Ragdoll model. Is there to limit the duplication of both instances to one?
Please help! Many thanks.
Character = script.Parent
Humanoid = Character.Student
Torso = Character.Torso
mode = Instance.new("Model")
mode.Name = "Player1"
mode.Parent = game.Workspace
backup = script.Parent:clone()
function OnDeath()
wait(0.00000001)
Humanoid.Parent = nil
if Torso then
zam=Torso:Clone()
zam.Parent=mode
x=Character:GetChildren()
for i=1,#x do
if ((x[i].Name=="Shirt") or (x[i].Name=="Pants")) then
local zor=x[i]:Clone()
zor.Parent=mode
end
if x[i].Name=="Head" then
local zem=x[i]:Clone()
zem.Parent=mode
local Neck = Instance.new("Weld")
Neck.Name = "Neck"
Neck.Part0 = zam
Neck.Part1 = zem
Neck.C0 = CFrame.new(0, 1.5, 0)
Neck.C1 = CFrame.new()
Neck.Parent = zam
end
if x[i].Name=="Right Arm" then
local Limb=x[i]:Clone()
Limb.Parent=mode
Limb.CFrame = zam.CFrame * CFrame.new(1.5, 0, 0)
local Joint = Instance.new("Glue")
Joint.Name = "RightShoulder"
Joint.Part0 = zam
Joint.Part1 = Limb
Joint.C0 = CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.C1 = CFrame.new(-0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.Parent = zam
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 = mode
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, -0.5, 0)
W.Parent = Limb
end
if x[i].Name=="Left Arm" then
local Limb=x[i]:Clone()
Limb.Parent=mode
Limb.CFrame = zam.CFrame * CFrame.new(-1.5, 0, 0)
local Joint = Instance.new("Glue")
Joint.Name = "LeftShoulder"
Joint.Part0 = zam
Joint.Part1 = Limb
Joint.C0 = CFrame.new(-1.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.C1 = CFrame.new(0, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.Parent = zam
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 = mode
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, -0.5, 0)
W.Parent = Limb
end
if x[i].Name=="Right Leg" then
local Limb=x[i]:Clone()
Limb.Parent=mode
Limb.CFrame = zam.CFrame * CFrame.new(0.5, -2, 0)
local Joint = Instance.new("Glue")
Joint.Name = "RightHip"
Joint.Part0 = zam
Joint.Part1 = Limb
Joint.C0 = CFrame.new(0.5, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.C1 = CFrame.new(0, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.Parent = zam
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 = mode
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, -0.5, 0)
W.Parent = Limb
end
if x[i].Name=="Left Leg" then
local Limb=x[i]:Clone()
Limb.Parent=mode
Limb.CFrame = zam.CFrame * CFrame.new(-0.5, -2, 0)
local Joint = Instance.new("Glue")
Joint.Name = "LeftHip"
Joint.Part0 = zam
Joint.Part1 = Limb
Joint.C0 = CFrame.new(-0.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.C1 = CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.Parent = zam
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 = mode
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, -0.5, 0)
W.Parent = Limb
end
bland=Instance.new("Humanoid")
bland.Health = 0
bland.MaxHealth = 0
bland.Parent=mode
bland.DisplayDistanceType = "None"
local int = Instance.new("StringValue")
int.Name = "AllowPick"
int.Value = ""
int.Parent = mode
if ((x[i].Name=="Shirt") or (x[i].Name=="Pants")) then
local zor=x[i]:Clone()
zor.Parent=mode
end
--[
if (x[i].ClassName=="CharacterMesh") then
local zor=x[i]:Clone()
zor.Parent=mode
end
if (x[i].ClassName=="Hat") then
local zor=x[i]:Clone()
zor.Parent=mode
end
local cam = Instance.new("Camera")
cam.Parent = game.Players:FindFirstChild(Character.Name)
cam.CameraSubject = mode.Humanoid
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 = zam.CFrame * CFrame.new(0, 0.5, 0)
Bar.Parent = mode
local Weld = Instance.new("Weld")
Weld.Part0 = zam
Weld.Part1 = Bar
Weld.C0 = CFrame.new(0, 0.5, 0)
Weld.Parent = zam
--]]
end
end
Character:Remove()
wait(120)
mode:Remove()
backup.Parent = workspace
if script.Parent then
script.Parent:Destroy()
end
end
Humanoid.Died:connect(OnDeath)

1 comment
Thanks ^_^