I am scripting a building kit and when I press the 'Refresh' button, it supposse to remove all parts in it that have a name of 'Part' and 'Thruss'. Then it suppose to make new parts in it but it is duplicating the parts more than once ;(
--//Services
local RS = game:GetService('ReplicatedStorage')
--//Variables
local Model = script.Parent.Parent
local CD = Model.Refresh.ClickDetector
local Clicked = false
--//Main
CD.MouseClick:connect(function()
if Clicked == false then
Clicked = true
for i,v in pairs(Model:GetChildren()) do
if v.Name == 'Part' or v.Name == 'Truss' then
v:Destroy()
print'1'
local CloneModel = RS:WaitForChild('BuildingKit') --Make sure the model is in ReplicatedStorage
for i,x in pairs(CloneModel:GetChildren()) do
if x.Name == 'Part' or v.Name == 'Truss' then
x:Clone().Parent = Model
print'2'
end
end
end
end
wait(5)
Clicked = false
end
end)

2 comments
Btw, this crashes my studio, guessing due to many parts being created
line 19, you have x.Name == 'Part' , v.Name == 'Truss" is the x and v on purpose?