This script is supposed to lengthen a shaft, moving the head of the shaft up each time it grows. But when I test the script, WAAYYY too many parts are created with lots of gaps. How can I fix this?
function Grow()
local debounce = false --My attempt at keeping loads of bricks from being made.
if debounce == false then
debounce = true
local findHard = game.Workspace:FindFirstChild("Shaft3")
if findHard then
print("coming")
else
local shaft = game.Workspace.Shaft --The shaft already exists.
local head = game.Workspace.Head --So does the head.
local grow1 = Instance.new("Part", game.Workspace) --Lengthening the shaft and moving the head up.
grow1.Name = "Shaft1"
grow1.Size = Vector3.new(3, 1, 2)
grow1.BrickColor = BrickColor.new("Carnation pink")
grow1.Anchored = true
head.Position = Vector3.new(1.5, 10, -3)
grow1.Position = Vector3.new(1.5, 9, -3)
wait(1)
local grow2 = Instance.new("Part", game.Workspace) --And again.
grow2.Name = "Shaft2"
grow2.Size = Vector3.new(3, 1, 2)
grow2.BrickColor = BrickColor.new("Carnation pink")
grow2.Anchored = true
head.Position = Vector3.new(1.5, 11, -3)
grow2.Position = Vector3.new(1.5, 10, -3)
wait(1)
local grow3 = Instance.new("Part", game.Workspace) --And again.
grow3.Name = "Shaft3"
grow3.Size = Vector3.new(3, 1, 2)
grow3.BrickColor = BrickColor.new("Carnation pink")
grow3.Anchored = true
head.Position = Vector3.new(1.5, 12, -3)
grow3.Position = Vector3.new(1.5, 11, -3)
end
debounce = false
end
end
game.Workspace.Shaft.Touched:connect(Grow) --Function fires when the shaft is touched.

1 comment
Probably because when you touch the brick, you are touching it a lot, and so the problem is that you don't have a wait in your script. I would add a wait at line 35, like wait(2) and then make the debounce false again, other wise it will keep looping