I want to clone anything (including humanoids, items, etc..) that touches my part. Can someone help me with this?
How do I clone anything that touches my part?
4 answers
The three answers above this are correct but you won't see anything until you clone soo many things it will lag down the game.
The correct way to Clone a touching part would be:
local Part = script.Parent -- Clone the item if if touched this part
local deBounce = false -- a check to stop any parts from spamming the touched event over and over
Part.Touched:Connect(function(hit)
if(deBounce == false) then -- check to see if anything has touched us before, if not then continue
deBounce = true -- We've been touched!
local Cne = hit:Clone() -- Clonbe the thing that touched us
Cne.Parent = workspace -- put the newlly created part inside the workspace
wait(1) -- wait a second
deBounce = false -- phew nothings touching us!
end
end)
If you wanted to stop the clones from creating clones of the one that touched the main part you would need to keep a record of all the cloned parts in a table and cycle through them and check to see if the touching part is one of the cloned parts.
something like:
local Clonies = {}
local Part = script.Parent -- Clone the item if if touched this part
local deBounce = false -- a check to stop any parts from spamming the touched event over and over
Part.Touched:Connect(function(hit)
local isClone = false
for k,v in pairs(Clonies) do
if(hit == v) then
isClone = true
break;
end
end
if(deBounce == false and isClone == false) then -- check to see if anything has touched us before, if not then continue
deBounce = true -- We've been touched!
local Cne = hit:Clone() -- Clonbe the thing that touched us
Cne.Parent = workspace -- put the newlly created part inside the workspace
Clonies[#Clonies+1] = Cne -- add this clone to our clones table
wait(1) -- wait a second
deBounce = false -- phew nothings touching us!
end
end)
hope this helps!
Use the .Touched event to detect when something is touched. Then use :Clone().
local Part = --(Part Location)--
local TouchingPart = --(The part that touched the original part)
Part.Touched:connect(function()
TouchingPart:Clone()
end)
1 comment
script.Parent.Touched:connect(function(hit))
local Part = script.Parent -- Clone the item if if touched this part
Part.Touched:Connect(function(hit)
hit:Clone()
end)
This way, anything that touches your part will be cloned.
Ok this is a bit interesting, because EVERYTHING that touches the part gets cloned (even the parts of you character).
(Server)Script in the part:
local ClonePart = script.Parent -- The part that clones everything
ClonePart.Touched:Connect(function(obj) -- Function fires, when an object touches the part
obj:Clone() -- Clone The part
end) -- End of function
Hopefully I can help... ;)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Oh yeah I forgot about debounce