Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make the clone disappear as player dies?

Asked by 3 years ago
Edited 3 years ago

I have this shadow clone script but whenever the character dies, the clone stays alive. How do I make it so when the character dies, the clone also dies? I have tried adding this in the function create clone and it doesn’t work.

https://www.roblox.com/library/6665350847/Shadow-Clone-Jutsu


game:GetService('Players').PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() dead(clone) end) end)

How do I make it so the clone dies?



local t = script.Parent local re = t:WaitForChild("RemoteEvent") local PS = game:GetService("PhysicsService") local path = game:GetService("PathfindingService") local rp = game:GetService("ReplicatedStorage") local folder = rp:WaitForChild("ShadowClone") function ChangeColl(p) if p:IsA("Part") or p:IsA("MeshPart") or p:IsA("BasePart") then PS:SetPartCollisionGroup(p, "Clone") end end function createp(p) local part = Instance.new("Part") part.Name = "CloneSmoke" part.Transparency = 1 part.Anchored = true part.CanCollide = false part.Size = Vector3.new(0.5,0.5,0.5) part.Position = p part.Parent = workspace.FX return part end function creates(p) local part = createp(p) local s = folder.Sound:Clone() s.Parent = part s:Play() game.Debris:AddItem(part, s.TimeLength) end function Clean(ctype, clone) if not clone.PrimaryPart then clone.PrimaryPart = clone:WaitForChild("HumanoidRootPart") end for i, v in pairs(clone:GetChildren()) do if (v:IsA("LocalScript") or v:IsA("Script")) or v:IsA("Tool") then v:Destroy() end end if ctype == Enum.HumanoidRigType.R6 then ctype = "R6" else ctype = "R15" end local Animate = folder:WaitForChild("Animate" .. ctype):Clone() Animate.Parent = clone end function deadeff(p) local part = createp(p) local smoke = folder.Smoke:Clone() smoke.Parent = part smoke:Emit(25) game.Debris:AddItem(part, 2) end function dead(clone) local hrp = clone.HumanoidRootPart deadeff(hrp.Position) creates(hrp.Position) t:SetAttribute("CloneIsAlive", false) clone:Destroy() end function CreateClone(ctype, c) c.Archivable = true local clone = c:Clone() Clean(ctype, clone) clone:SetPrimaryPartCFrame(c.PrimaryPart.CFrame * CFrame.new(-3.5,0,0)) for i,v in pairs(clone:GetDescendants()) do ChangeColl(v) end clone.Parent = workspace.Clones clone.Name = c.Name .. " Clone" local hum = clone:WaitForChild("Humanoid") local hrp = clone:WaitForChild("HumanoidRootPart") creates(hrp.Position) hum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None hum.MaxHealth = 1 hum.Health = 1 hum.Died:Connect(function() dead(clone) end) local smoke = folder.Smoke:Clone() smoke.Parent = hrp smoke:Emit(25) return clone end function GetEnemy(c, clone) local chrp = clone:WaitForChild("HumanoidRootPart") local hrp = c.HumanoidRootPart for i,v in pairs(workspace:GetDescendants()) do if v:IsA("Model") and v ~= clone and v ~= c and v:FindFirstChild("HumanoidRootPart") and v:FindFirstChild("Humanoid") and v.Humanoid:GetState() ~= Enum.HumanoidStateType.Dead then if v:findFirstChild("HumanoidRootPart") and (hrp.Position - v.HumanoidRootPart.Position).Magnitude <= t:GetAttribute("Range") then return v end end end return nil end function CloneFollow(c, clone) local chum = clone:WaitForChild("Humanoid") coroutine.resume(coroutine.create(function() while clone:IsDescendantOf(workspace.Clones) and chum and chum:GetState() ~= Enum.HumanoidStateType.Dead do if not clone:FindFirstChild("HumanoidRootPart") then break end local enemy = GetEnemy(c, clone) if enemy and enemy:findFirstChild("HumanoidRootPart") and clone:findFirstChild("HumanoidRootPart") then clone.HumanoidRootPart.CFrame = CFrame.lookAt(clone.HumanoidRootPart.Position, enemy.HumanoidRootPart.Position) if (enemy.HumanoidRootPart.Position - clone.HumanoidRootPart.Position).Magnitude > 5 then chum:MoveTo(enemy.HumanoidRootPart.Position) chum.MoveToFinished:Wait(1) else if enemy:findFirstChild("Humanoid") and clone:findFirstChild("deb") == nil then local tra = Instance.new("Animation") tra.AnimationId = "rbxassetid://" -- Your punch animation here local a = chum:LoadAnimation(tra) a:Play() enemy.Humanoid:TakeDamage(t:GetAttribute("Damage")) local deb = Instance.new("BoolValue", clone) deb.Name = "deb" game.Debris:AddItem(deb, 0.3) end end else chum:MoveTo(c.HumanoidRootPart.CFrame * CFrame.new(-3.5,0,0).p) chum.MoveToFinished:Wait(1) end wait() end end)) end function Serv(plr) local c = plr.Character local hum = c:WaitForChild("Humanoid") local ctype = hum.RigType t:SetAttribute("CloneIsAlive", true) local clone = CreateClone(ctype, c) CloneFollow(c, clone) end re.OnServerEvent:Connect(Serv)
0
What is dead(Clone), I never heard of that function before JustinWe12 723 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

I dont think dead() is a function. You can replicate the death of the clone by simply destroying the clone. Instead of

dead(clone)

do:

clone:Destroy()
0
dead(clone) is a function created in the script (the longer code snippet) appxritixn 2235 — 3y
Ad

Answer this question