Part cloning when other parts are deleted

So, I made a script that checks when a child in workspace is removed, and if that child is specified child then it will cone. except when anything is deleted, it still clones

local check_for2 = { 
	"AECMD",
}
local aecmdran = false
game.Workspace.ChildRemoved:Connect(function(ChildRemoved)
	local shouldbe3 = table.find(check_for2, "AECMD") 
	if not shouldbe3 then
		return
	end
	if shouldbe3 then
		if aecmdran == true then
			return
		end
		if aecmdran == false then
			script:FindFirstChild("AECMD"):Clone().Parent = game.Workspace
			aecmdran = true
			wait(5)
			aecmdran = false
			
		end
	
	end
end)
1 Like

so what are you trying to get? i dont understand what you are trying to achieve

When a part is being deleted, named specified part, it will clone that part back to workspace.

im pretty sure there isnt a set position of where the clone will go, idk if it goes to where it was before but (maybe?) it goes to 0, 0, 0

Wrong actually.

wait()
local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function()
	pcall(function()
		game.Workspace.AECMD.CFrame = game.Players.AmericanEagle124579.Character.HumanoidRootPart.CFrame * CFrame.new(-3,2,-6)
	end)
	end)
	

but isnt this for the position of the old part? you didnt move the position of the clone

No actually, the script is inside of the part, telling it it’s position

image

i recommend making it instead of looking in workspace for the part, just do script.parent, since if there is multiple

You don’t understand tho, the part is cloning multiple times. It’s only supposed to clone once. It literally clones when anything but the part is deleted.

is it cloning after the debounce is over? or is it rapidly cloning

No. It’s cloning even when something that isnt the part is removed from workspace.

would there be a way to make it say __ part was removed! or something? i wanna see where this is happening

You could paste in the part checker yourself, just replace aecmd with your part name then use a script to delete a totally random part. it will clone its self even tho it wasnt removed.

maybe use a different method of seeing if the part is what you want it to be?

because you put when anything is removed with this line …
Try this whole thing in a folder from the workspace and call that folder not the workspace.

he is checking after seeing childremoved if it is the right part, so i doubt this is the answer

I’m checking workspace, not a folder.

I found out a way to do it:

local check_for2 = { 
	"AECMD",
}
local aecmdran = false

game.Workspace.ChildRemoved:Connect(function(ChildRemoved)
	if ChildRemoved.Name ~= "AECMD" then
		-- The removed child is not the script we're looking for
		return
	end

	if aecmdran then
		-- The script has already been cloned
		return
	end

	-- Clone the script and add it back to the workspace
	script:FindFirstChild("AECMD"):Clone().Parent = game.Workspace
	aecmdran = true
	wait(5)
	aecmdran = false
end)

I used ai to help me correct this. Remember: This is tested and works. I just want to clarify that this is AI generated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.