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

Why Does This Script Generate Lots of Random Parts?

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

0

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

1 answer

function Grow()
	local debounce = false

You effectively have no debounce, since you always set it back to false each time the function runs. Since it's always false, the if statement will always run.

You need to define it outside the function, so that won't happen.

local debounce = false

function Grow()

I also recommend adding a few seconds before you enable your debounce again, just to be sure.

wait(3)
debounce = false

If your positioning is wrong I can't really help with that.

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