How to make a Once() but not using Once()?


So, when I clicked a potion I can’t change the potion I have to use it so I need to put the db somewhere else but idk where, Idk if im clear im sorry

and the db I put it when the button “use” is clicked

local function OnBoostClicked(BoostInfo, clickedButton)
	local UseDB = false
	if BtnBoostDB == false then
		InfoFrame.AuraFrame.BoostImage.Image = BoostInfo.image
		InfoFrame.BoostName.Text = BoostInfo.name
		InfoFrame.BoostName.TextColor3 = BoostInfo.textColor
		InfoFrame.BoostName.Font = BoostInfo.textFont
		InfoFrame.rng.Text = "X" .. tostring(BoostInfo.Multiplier)
		InfoFrame.Luck.Text = ""
		InfoFrame.Speed.Text = ""

		InfoFrame.EquipButton.MouseButton1Click:Connect(function()
			if UseDB == false then
				UseDB = true
				BtnBoostDB = true
				if clickedButton == lastClickedBoost then
					if lastClickedBoost == nil then return end
					BoostCount -= 1
					giveBoost(BoostInfo.name)
					updateBoostAmount(clickedButton)
					updateMaxBoostText()
					OnBoostClicked(BoostInfo, clickedButton)
					clickedButton.Active = true
					clickedButton.Interactable = true
					local ValBoost = player.Boosts:FindFirstChild(clickedButton.Name)
					if ValBoost.Value <= 0 then
						clickedButton:Destroy()
						lastClickedBoost = nil
						clickedButton = nil
						InfoFrame.AuraFrame.BoostImage.Image = ""
						InfoFrame.AuraFrame.auraNameText.Text = ""
						InfoFrame.BoostName.Text = ""
						InfoFrame.rng.Text = "X"
						task.wait(0.5)
						UseDB = false
					else
						lastClickedBoost = nil
						clickedButton = nil
						task.wait(0.5)
						UseDB = false
					end
				end 
			end
		end)
	else
		return
	end
end
1 Like

Make sure UseDB is used throughout.
Change BtnBoostDB to UseDB in the second line.

You have used UseDB = false twice. One in each section of the if ValBoost.Value <= 0 loop.
Just remove the UseDB variables inside the condition and change the value outside, once.
Like so:

if ValBoost.Value <= 0 then
    clickedButton:Destroy()
    lastClickedBoost = nil
    clickedButton = nil
    InfoFrame.AuraFrame.BoostImage.Image = ""
    InfoFrame.AuraFrame.auraNameText.Text = ""
    InfoFrame.BoostName.Text = ""
    InfoFrame.rng.Text = "X"
end

lastClickedBoost = nil
clickedButton = nil
task.wait()
UseDB = false

I have also changed repeated statements and put them outside the loop because thwy will be ran either way.

And why are you using the debounce check for false, twice? (in the first and second if-statement)

I checked the db twice cause its just not the same db I wanted to put db when I click the button “EquipButton” but that was not working so I deleted it and I just have 1 db now

How can we return end a function outside of it ? becuase I got an idea but idk how to return end a function outside of it.


local db=true --before the function or loop
local function OnBoostClicked(BoostInfo, clickedButton)
	if BtnBoostDB == true then
		InfoFrame.AuraFrame.BoostImage.Image = BoostInfo.image
		InfoFrame.BoostName.Text = BoostInfo.name
		InfoFrame.BoostName.TextColor3 = BoostInfo.textColor
		InfoFrame.BoostName.Font = BoostInfo.textFont
		InfoFrame.rng.Text = "X" .. tostring(BoostInfo.Multiplier)
		InfoFrame.Luck.Text = ""
		InfoFrame.Speed.Text = ""

		InfoFrame.EquipButton.MouseButton1Click:Connect(function()
			if db then db=false --right after the click

				InfoFrame.EquipButton.Interactable = false
				if clickedButton == lastClickedBoost then
					if lastClickedBoost == nil then return end
					BoostCount -= 1
					giveBoost(BoostInfo.name)
					updateBoostAmount(clickedButton)
					updateMaxBoostText()
					OnBoostClicked(BoostInfo, clickedButton)
					clickedButton.Active = true
					clickedButton.Interactable = true
					local ValBoost = player.Boosts:FindFirstChild(clickedButton.Name)
					if ValBoost.Value <= 0 then
						clickedButton:Destroy()
						lastClickedBoost = nil
						clickedButton = nil
						InfoFrame.AuraFrame.BoostImage.Image = ""
						InfoFrame.AuraFrame.auraNameText.Text = ""
						InfoFrame.BoostName.Text = ""
						InfoFrame.rng.Text = "X"
						task.wait(0.1)
						InfoFrame.EquipButton.Interactable = true
					else
						task.wait(0.1)
						InfoFrame.EquipButton.Interactable = true
						lastClickedBoost = nil
						clickedButton = nil
					end
				end

				task.wait(2) --whatever pause works
                db=true
			end
		end)
	else
		return
	end
end
1 Like

Thank you so muchh, it worked !!!

1 Like

I noticed you said something about 2 db’s (debounces) Not sure what you meant there …
Just pointing out each debounce is solo only. If you need 2 you have to use 2 different variables.
db1 db2 db3 …

This is actually a flag variable using a conditional bounce technique. I guess we call that a debounce now.

1 Like

Yeah I wanted to use one db for the first button when I click on the potion and a second when I click on “Use” button so ty :slight_smile:

1 Like