Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i clone only one part after it was touched?

So i tried to make a part that will killed you if you touch it This is the script

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid").Health the
hit.Parent:FindFirstChild("Humanoid).Health = hit.Parent:FindFirstChild("Humanoid").Health - 100
local part = workspace.Part
script.Parent:Destroy()
local copy = part:Clone()
copy.Parent = part.Parent
copy.Position = Vector3.new(10,20,10)
end)

Last time i tried this , The part keep cloning a part and crashed my studio instantly

1 answer

✓ Accepted answer

you can add a variable that makes the function run once like this :

local already_cloned = false -- we will use this variable to make the script excute once only.

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid").Health then
	 if already_cloned == false then -- if we havent cloned before then
hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 100
local part = workspace.Part
script.Parent:Destroy()
local copy = part:Clone()
copy.Parent = part.Parent
copy.Position = Vector3.new(10,20,10)
  already_cloned = true --after we clone once then "already_cloned" should be set to true since we already cloned it and dont want to clone again.
 end
    end
end)

4 comments

0

Would return errors if any part touched it that didn't have a humanoid

0

I already tried to use Debounce but that doesn't work for somehow

0

this isnt debounce, this is similiar but it wont make you clone it again, ever.

0

if thats what you want

This discussion is preserved as it was. New answers, comments, and votes are closed.