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

How do I clone anything that touches my part?

Asked by 4 years ago

I want to clone anything (including humanoids, items, etc..) that touches my part. Can someone help me with this?

4 answers

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago
Edited 4 years ago

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:

01local Part = script.Parent -- Clone the item if if touched this part
02local deBounce = false -- a check to stop any parts from spamming the touched event over and over
03Part.Touched:Connect(function(hit)
04    if(deBounce == false) then -- check to see if anything has touched us before, if not then continue
05        deBounce = true -- We've been touched!
06        local  Cne = hit:Clone() -- Clonbe the thing that touched us
07        Cne.Parent = workspace -- put the newlly created part inside the workspace
08        wait(1) -- wait a second
09        deBounce = false -- phew nothings touching us!
10    end
11end)

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:

01local Clonies = {}
02local Part = script.Parent -- Clone the item if if touched this part
03local deBounce = false -- a check to stop any parts from spamming the touched event over and over
04Part.Touched:Connect(function(hit)
05    local isClone = false
06    for k,v in pairs(Clonies) do
07        if(hit == v) then
08            isClone = true
09            break;
10        end
11    end
12    if(deBounce == false and isClone == false) then -- check to see if anything has touched us before, if not then continue
13        deBounce = true -- We've been touched!
14        local  Cne = hit:Clone() -- Clonbe the thing that touched us
15        Cne.Parent = workspace -- put the newlly created part inside the workspace
16        Clonies[#Clonies+1] = Cne -- add this clone to our clones table
17        wait(1) -- wait a second
18        deBounce = false -- phew nothings touching us!
19    end
20end)

hope this helps!

0
Oh yeah I forgot about debounce DaBagelBoy 90 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Use the .Touched event to detect when something is touched. Then use :Clone().

1local Part = --(Part Location)--
2local TouchingPart = --(The part that touched the original part)
3 
4Part.Touched:connect(function()
5    TouchingPart:Clone()
6end)
0
script.Parent.Touched:connect(function(hit)) LEADERFORXXDDPL 0 — 4y
Log in to vote
0
Answered by
Soban06 410 Moderation Voter
4 years ago
1local Part = script.Parent -- Clone the item if if touched this part
2 
3Part.Touched:Connect(function(hit)
4    hit:Clone()
5end)

This way, anything that touches your part will be cloned.

Log in to vote
0
Answered by 4 years ago

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:

1local ClonePart = script.Parent -- The part that clones everything
2 
3ClonePart.Touched:Connect(function(obj) -- Function fires, when an object touches the part
4    obj:Clone() -- Clone The part
5end) -- End of function

Hopefully I can help... ;)

Answer this question