How do i add a buffer

I want to add a buffer in my script but its not working the way my brain works and i dont know what to do.

The script is

E = true

For i, Button in pairs(frame:getchildren()) do

If Button:IsA(“TextButton”) and e = true then
Button:MouseButton1Click:Connect(function()
E = false
Wait (5)
E = true

Purpose: i want to make a button that when i click on it, it runs code but theres a 4 second cool down

Note:

I am looking for answers and full ones help me learn but if you dont its fine just make your explanation super simple!

You’re really close. It’s a debounce, not a buffer though. The terminology comes from electronics, where certain types of input can be sporatic and mess up your input if you don’t add a cooldown like you want. This is the only change I see that you need to make.

E = true
for i, Button in pairs(frame:GetChildren()) do
    if Button:IsA(“TextButton”) then
        Button.MouseButton1Click:Connect(function()
            if E == true then -- this line here
                E = false
                wait (5)
                E = true
            end
        end)
    end
end

I also cleaned up the code a little and fixed a couple of minor mistakes.

Ignore this post, I am making a new one.

LocalScript:4: expected ‘then’ when parsing if statment, got “-“ error

local frame = script.Parent
local toggle = false

for _, button in pairs(frame:GetChildren()) do
	if button:IsA("TextButton") then
		button.MouseButton1Click:Connect(function()
			if toggle then
				task.wait(5)
				toggle = false
			elseif not toggle then
				toggle = true
				task.wait(5)
				toggle = false
			end
		end)
	end
end

I believe I’ve fixed the issue.

I got an error. You can see the error above. However, ill copy paste and if that works its official

Where would i put my scripts? Can you use an example of “print”

So that it prints something?

Your script has an issue

Are you trying to make the buttons toggle the visibility of the frame?

Thank you, but the script you wrote has the same flaw as his. When you click the button it will have a 5 second delay after first click but after that it will let you click unlimited. Please take resetting in account as well

That and i want it to activate the other script. Its a ‘press play’ play button.

Edit: bassicialy the entire game is about pressing a block and once you press the block the game ends and you get 1 point added to your name. When the game ends you have the option to “play again.” I was going to try to sell admin or something as well. I’m doing it more for the learning than the fun or money

local frame = script.Parent
frame.Visible = false
local toggle = false

for _, button in pairs(frame:GetChildren()) do
	if button:IsA("TextButton") then
		button.MouseButton1Click:Connect(function()
			if toggle then
				toggle = false
				frame.Visible = false
			elseif not toggle then
				toggle = true
				frame.Visible = true
			end
		end)
	end
end

Your script doesn’t mention any other scripts but will make all the buttons inside the “Frame” instance when clicked toggle the visibility of the frame. Make sure the script is a local script placed inside the frame.

By the way i suggested you check the previous message i sent, for i edited it.

Edit: can i just do a simple loop? I dont know why theres so much extra anyways

maybe this will work?

local frame = script.Parent
frame.Visible = false

for _, button in pairs(frame:GetChildren()) do
	if button:IsA("TextButton") then
		button.MouseButton1Click:Connect(function()
			if button:GetAttribute("Deb") then return end
			button:SetAttribute("Deb",true)
			frame.Visible = not frame.Visible
			wait(5)
			button:SetAttribute("Deb",false)
		end)
	end
end