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:

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!

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().

local Part = --(Part Location)--
local TouchingPart = --(The part that touched the original part)

Part.Touched:connect(function()
    TouchingPart:Clone()
end)
0
script.Parent.Touched:connect(function(hit)) LEADERFORXXDDPL 0 — 4y
Log in to vote
0
Answered by
Soban06 410 Moderation Voter
4 years ago
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.

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:

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... ;)

Answer this question