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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
crueluu 169
3 years ago

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)
0
Would return errors if any part touched it that didn't have a humanoid Raccoonyz 1092 — 3y
0
I already tried to use Debounce but that doesn't work for somehow Eager_Face 4 — 3y
0
this isnt debounce, this is similiar but it wont make you clone it again, ever. crueluu 169 — 3y
0
if thats what you want crueluu 169 — 3y
Ad

Answer this question