Problem with Debounce and Visible Table Values

I’ve been making a script for Animations that I could apply to my Gui but something doesn’t work. I’ve searched everything: DevForum, ChatGPT ( You could never know ), Internet, etc…

I noticed that the Values for VISIBLE and DEBOUNCE never Changed.
And I don’t know why that is happening!

Here are the Values after clicking the Button multiple times:

image

Any help is appreciated :slight_smile:

Here is the Script:

-- Services

local PLAYERS = game:GetService("Players")
local TWEENSERVICE = game:GetService("TweenService")
local RP = game:GetService("ReplicatedStorage")

-- Variables

local GUI = script.Parent
local MAIN_FRAME = GUI:WaitForChild("Main")
local BUTTONS_HOLDER = MAIN_FRAME:WaitForChild("ButtonsHolder")
local TOGGLE = MAIN_FRAME:WaitForChild("Toggle")

-- (Folders)

local SOZNDS = GUI:WaitForChild("Sounds")
local MODULES = GUI:WaitForChild("Modules")

-- Modules

local TWEENMODULE = require(MODULES:WaitForChild("UIFeatures"))

-- Tables

local CURRENT_DEBOUNCES = {

	["TOGGLE"] = false

}

local CURRENT_VISIBLE = {

	["MAIN_FRAME"] = false

}

-- Functions

local function TWEEN_TOGGLE_UP_DOWN(INSTANCE, VISIBLE, DEBOUNCE)

	if DEBOUNCE then return end

	local TI = TweenInfo.new(.2, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut)

	if VISIBLE then

		DEBOUNCE = true

		local TWEEN = TWEENSERVICE:Create(INSTANCE, TI, {Position = UDim2.new(.5, 0, 0.9, 0)})

		TWEEN:Play()

		TWEEN.Completed:Wait()


		VISIBLE = not VISIBLE
		DEBOUNCE = false

		return

	else

		DEBOUNCE = true

		local TWEEN = TWEENSERVICE:Create(INSTANCE, TI, {Position = UDim2.new(.5, 0, 1.06, 0)})

		TWEEN:Play()

		TWEEN.Completed:Wait()

		VISIBLE = not VISIBLE
		DEBOUNCE = false

		return

	end

end

-- TODO: Make Hover Animation

TOGGLE.MouseButton1Click:Connect(function()

	TWEEN_TOGGLE_UP_DOWN(MAIN_FRAME, CURRENT_VISIBLE.MAIN_FRAME, CURRENT_DEBOUNCES.TOGGLE)

end)

This runs the code. I’ve put several prints after that and the code ran, so that can’t be the problem.

Also, the Values don’t even change as you can see in the attached Image

It’s because you’re setting DEBOUNCE, a local variable declared inside function TWEEN_TOGGLE_UP_DOWN’s scope, not CURRENT_DEBOUNCES["TOGGLE"].

I’ve changed it to this. Still doesn’t work:

local function TWEEN_TOGGLE_UP_DOWN(INSTANCE, VISIBLE, DEBOUNCE)

   if DEBOUNCE then return end

   local TI = TweenInfo.new(.2, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut)
   
   print(string.format("Debounce: %s\nVisible: %s", tostring(CURRENT_DEBOUNCES[DEBOUNCE]), tostring(CURRENT_VISIBLE[VISIBLE])))

   if VISIBLE == true then

   	CURRENT_DEBOUNCES[DEBOUNCE] = not CURRENT_DEBOUNCES[DEBOUNCE]

   	local TWEEN = TWEENSERVICE:Create(INSTANCE, TI, {Position = UDim2.new(.5, 0, 0.9, 0)})

   	TWEEN:Play()

   	TWEEN.Completed:Wait()

   	return CURRENT_VISIBLE[VISIBLE] == not CURRENT_VISIBLE[VISIBLE], CURRENT_DEBOUNCES[DEBOUNCE] == false

   else

   	DEBOUNCE = true

   	local TWEEN = TWEENSERVICE:Create(INSTANCE, TI, {Position = UDim2.new(.5, 0, 1.06, 0)})

   	TWEEN:Play()

   	TWEEN.Completed:Wait()

   	return CURRENT_VISIBLE[VISIBLE] == not CURRENT_VISIBLE[VISIBLE], CURRENT_DEBOUNCES[DEBOUNCE] == false

   end

end

-- TODO: Make Hover Animation

TOGGLE.MouseButton1Click:Connect(function()

   TWEEN_TOGGLE_UP_DOWN(MAIN_FRAME, "MAIN_FRAME", "TOGGLE")

end)

A different problem has been introduced: you use both DEBOUNCE and CURRENT_DEBOUNCES[DEBOUNCE]. Instead, you should only ever use the latter.

Now I’m really confused. Can u explain it in the code?

You simply forgot to make all the appropriate changes.

-- This function is called with (MAIN_FRAME, "MAIN_FRAME", "TOGGLE")
local function TWEEN_TOGGLE_UP_DOWN(INSTANCE, VISIBLE, DEBOUNCE)

   -- DEBOUNCE will always be "TOGGLE",
   -- meaning the function will return.
   if DEBOUNCE then return end

   -- We should do
   if CURRENT_DEBOUNCES[DEBOUNCE] then return end
   -- instead.
end

How is this printing the Values then?!

Nani!?

And what is the message being logged to the output? (would be helpful if you printed DEBOUNCE as well)

image

Nvm, my friend took a look at it and It works now. Thank you for being so helpful anyways :slight_smile:

Here is the working code:

-- Services

local PLAYERS = game:GetService("Players")
local TWEENSERVICE = game:GetService("TweenService")
local RP = game:GetService("ReplicatedStorage")

-- Variables

local GUI = script.Parent
local MAIN_FRAME = GUI:WaitForChild("Main")
local BUTTONS_HOLDER = MAIN_FRAME:WaitForChild("ButtonsHolder")
local TOGGLE = MAIN_FRAME:WaitForChild("Toggle")

-- (Folders)

local SOZNDS = GUI:WaitForChild("Sounds")
local MODULES = GUI:WaitForChild("Modules")

-- Modules

local TWEENMODULE = require(MODULES:WaitForChild("UIFeatures"))

-- Tables

local CURRENT_DEBOUNCES = {
	["TOGGLE"] = false
}

local CURRENT_VISIBLE = {
	["MAIN_FRAME"] = false
}

-- Functions
local function TWEEN_TOGGLE_UP_DOWN(INSTANCE, VISIBLE_KEY, DEBOUNCE_KEY)
	
	if CURRENT_DEBOUNCES[DEBOUNCE_KEY] then	return end		

	local TI = TweenInfo.new(.2, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut)

	if CURRENT_VISIBLE[VISIBLE_KEY] then
		
		CURRENT_DEBOUNCES[DEBOUNCE_KEY] = true

		local TWEEN = TWEENSERVICE:Create(INSTANCE, TI, {Position = UDim2.new(.5, 0, 0.9, 0)})
		
		TWEEN:Play()

		TWEEN.Completed:Wait()

		CURRENT_VISIBLE[VISIBLE_KEY] = not CURRENT_VISIBLE[VISIBLE_KEY]
		
		CURRENT_DEBOUNCES[DEBOUNCE_KEY] = false
		
	else
		
		CURRENT_DEBOUNCES[DEBOUNCE_KEY] = true
		

		local TWEEN = TWEENSERVICE:Create(INSTANCE, TI, {Position = UDim2.new(.5, 0, 1.06, 0)})
		
		TWEEN:Play()

		TWEEN.Completed:Wait()

		CURRENT_VISIBLE[VISIBLE_KEY] = not CURRENT_VISIBLE[VISIBLE_KEY]
		
		CURRENT_DEBOUNCES[DEBOUNCE_KEY] = false
		
	end
	
end

-- TODO: Make Hover Animation

TOGGLE.MouseButton1Click:Connect(function()
	
	TWEEN_TOGGLE_UP_DOWN(MAIN_FRAME, "MAIN_FRAME", "TOGGLE")
	
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.