How to make a script to counteract a issue that I face?

This is my script, when the part gets removed, it clones it self back. But heres the issue tho, it clones its self multiple times. can someone maybe help?

local check_for2 = { 
	"AECMD",

}


	game.Workspace.ChildRemoved:Connect(function(ChildRemoved)
		local should_be2 = table.find(check_for2,"AECMD")

		if should_be2 then
			
			script.AECMD:Clone().Parent = game.Workspace
		end
	end)
end

You could use :Once instead of :Connect to only clone it once. Your if statement is odd, it should always evaluate to true, why do you find AECMD in the table above?

AECMD is the name of a part. I want to check if when a child is removed from workspace, that it isnt my part, and if it is, it would be cloned back to workspace. I play a lot of script building games.

Ok then you should be using this instead, and if you want to use the table as a long list of items to check for try the second part

-- 1st just one implementation
if ChildRemoved.Name == "AECMD" then

-- 2nd long list implementation
if table.find(check_for2, ChildRemoved.Name) then
    script:FindFirstChild(ChildRemoved.Name):Clone().Parent = game.Workspace
end

I’m sorry, I don’t understand what i replace what with.

here is the full script I think you want

	local check_for2 = { 
		"AECMD",
	}

	game.Workspace.ChildRemoved:Connect(function(ChildRemoved)
		if table.find(check_for2, ChildRemoved.Name) then
			script:FindFirstChild(ChildRemoved.Name):Clone().Parent = game.Workspace
		end
	end)
end

Thank you, sorry, I occasionally cant comprehend things like that sometimes.

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