How would i make it so that a clone part doesnt do the same thing as the main script?

local part = script.Parent
local debounce = false

part.Touched:Connect(function(random)
	local humanoid = random.Parent:FindFirstChild("Humanoid")
	if debounce then
		return
	end
	if humanoid then
		debounce = true
		for i = 1,10 do	
			local x = math.random(1,200)
			print(x)
		local y = 100
		local z = math.random(1,500)
		local PartClone = part:Clone() 
		PartClone.Parent = workspace
		PartClone.Position = Vector3.new(x,y,x)
		wait()
		end
	end
end)

Code i have so far.

Works well but this allows it so when the cloned parts are touched, they make more cloned parts which is what i dont want

1 Like

You see script.Parent.
When the part is cloned the same script is added as the child of the cloned part which creates a connection object on Touched with it’s Parent.
Instead parent the script to something like ServerScriptService.
From there add the path to the default part.

1 Like

There’s 1 thing about that though

Example:

local part = script.Parent
local debounce = false

part.Touched:Connect(function(random)
	local humanoid = random.Parent:FindFirstChild("Humanoid")
	if debounce then
		return
	end
	if humanoid then
		debounce = true
		for i = 1,50 do	
		local x = math.random(1,200)	
		local y = 100
		local z = math.random(1,200)
		local PartClone = part:Clone() 
		PartClone.Parent = workspace
			PartClone.Position = Vector3.new(x, y ,z)
                        humanoid.Health = humanoid.Health - 10
			print(x)
			print(z)
		wait()
		end
	end
end)

I added something to decrease humanoid hp.
What if i wanted that to move on to the cloned parts but not the script that makes them clone more?

1 Like

Create separate Connection with cloned part.
example -

local main = workspace.Main  -- referring to the part that can clone 


local function hp(hit)
	-- your code
end

local function onTouched(hit) 
	local clone = main:Clone() -- cloned the main part
	--[[ ... ]]
	-- now creating seperate connection with the cloned part 
	clone.Touched:Connect(hp)
end
 

thanks! but i dont know what that really means.

Sorry for not clarifying that off.
That is the rest of the code you want to write after cloning.
I should have just wrote --rest of the code instead of that ellipsis.