Debounce not working or error when using wait

Hello, I need help with a problem. My problem is that the anti-bounce does not work or the “Wait” is the one that does not work. Pressing a key should open a menu and if the key receives spam a failure is made, and for that I want the anti-bounce but it does not work, or directly the “Wait” does not work.

local Mapa = script.Parent.Mapa
local Open = false
local keyText = "M"
local blur = Instance.new("BlurEffect",game.Workspace.CurrentCamera)
blur.Size = 0
local Opciones = script.Parent.Opciones
local buttonPressed = false
local tiempo = 545
local Value = script.Parent.Parent:WaitForChild("Speed")
local WalkSpeed = script.Parent.Parent:WaitForChild("WalkSpeed")

local MenuKey = game.Players.LocalPlayer:WaitForChild("Keys"):WaitForChild("MenuKey")

local PositionClosed = UDim2.new(0.11, 0,0.9, 0)
local PositionOpen = UDim2.new(0.5, 0,0.84, 0)
local SizeClosed = UDim2.new(0.2, 0, 0.17, 0)
local SizeOpen = UDim2.new(0.9, 0, 0.7, 0)

local UserInputService = game:GetService("UserInputService")

local Ajustes = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Configuracion")

UserInputService.InputBegan:connect(function(key)
	if (key.KeyCode.Name == keyText) then
		if Open then
			Open = false
			blur.Size = 0
			buttonPressed = true
			script.Parent.Back.Visible = true
			script.Parent.Back2.Visible = true
			script.Parent.Inventario.Visible = false
			script.Parent.Donaciones.Visible = false
			script.Parent.Jugador.Visible = false
			script.Parent.Mapa.Visible = true
			Ajustes.Enabled = false
			script.Parent.Informacion.Visible = false
			script.Parent.Frame.Visible = false
			script.Parent.Mapa.ImageLabel.Visible = true
			script.Parent.Mapa.Minimap2.Visible = false
			script.Parent.Mapa.Minimap.Visible = true
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 7
			script.parent.Parent.ColorBlur.Visible = false
			script.Parent.Parent.Slots.Visible = false
			script.parent.Parent.Nivel.Visible = true
			Ajustes:WaitForChild("Ajustes"):WaitForChild("Sonido"):WaitForChild("Volumenui"):WaitForChild("Frame"):WaitForChild("uicerrar"):Play()
			script.parent.Parent.VerPlayer.Visible = true
			script.Parent.Parent.Slots.Visible = true
			script.Parent.Parent.Hora.Visible = true
			Value.Value = 20
			WalkSpeed.Value = 7
			script.Parent.Mapa.Minimap.Iconos:TweenSize(UDim2.new(1, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.6, true)
			Opciones:TweenPosition(UDim2.new(0.5, 0,-1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.6, true)
			Mapa:TweenSize(SizeClosed, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.6, true)
			wait(0.4)
			Mapa:TweenPosition(PositionClosed, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.6, true)
			wait(tiempo)
				script.Parent.Mapa.Minimap.Camara.MaxAxisFieldOfView = 60
				buttonPressed = false
			else
			Open = true
			Mapa:TweenPosition(PositionOpen, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.6, true)
			blur.Size = 15
			buttonPressed = true
			script.Parent.Back.Visible = false
			script.Parent.Back2.Visible = false
			script.Parent.Mapa.ImageLabel.Visible = false
			script.Parent.Donaciones.Visible = false
			script.Parent.Mapa.Minimap2.Visible = true
			script.Parent.Mapa.Minimap.Visible = false
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
			script.parent.Parent.ColorBlur.Visible = true
			script.parent.Parent.VerPlayer.Visible = false
			script.parent.Parent.Nivel.Visible = false
			script.Parent.Parent.Slots.Visible = false
			script.Parent.Parent.Hora.Visible = false
			Ajustes:WaitForChild("Ajustes"):WaitForChild("Sonido"):WaitForChild("Volumenui"):WaitForChild("Frame"):WaitForChild("UI"):Play()
			Value.Value = 0
			WalkSpeed.Value = 0
			script.Parent.Mapa.Minimap.Iconos:TweenSize(UDim2.new(0.65, 0, 0.65, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.6, true)
			Opciones:TweenPosition(UDim2.new(0.5, 0,0.1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.6, true)
			wait(0.4)
			Mapa:TweenSize(SizeOpen, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.6, true)
			wait(tiempo)
			warn("Why Doesn't working :(")
			script.Parent.Mapa.Minimap.Camara.MaxAxisFieldOfView = 120
			buttonPressed = false
		end
	end
end)

I think the issue is that your denounce is backwards.

Try this:

if not Open then
     Open = true
     --Rest the open code
else
     Open = false
     --Rest of spam code
end

Also what is buttonPressed used for?

not pro gamers:

pro gamers:

Open = not Open
4 Likes

Oh wow that is way more simple. You learn something new everyday I guess.