Debounce is not working properly

Well sorry for making another post like it, but I need this to save scripts and memory. The anti-bounce does not work, it does not activate when pressing the text button, or changing it does not activate the script, I would really appreciate if you could help me.

local Icon = script.Parent:WaitForChild("Icon")
local Button = script.Parent
local OpenPosition = UDim2.new(0.85, 0, 0.5, 0)
local ClosePosition = UDim2.new(0.15, 0, 0.5, 0)
local tiempo = 0.3
local Debounce = false
local TweenService = game:GetService("TweenService")
local Fire = game:GetService("ReplicatedStorage"):WaitForChild("ConfiguracionGeneral"):WaitForChild("JuegoConfg")
local time = 1
local GUISave = game:WaitForChild("ReplicatedStorage"):WaitForChild("GUI"):WaitForChild("FrameSave")
local StringValueObject = script.Parent:WaitForChild("Take")

-- es el de Encendido
script.Parent.MouseButton1Click:Connect(function()
	if not Debounce then return end
	Debounce = true
	if StringValueObject.Value == "True" then
		Icon:TweenPosition(OpenPosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeOut = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(0.501961, 1, 0.501961)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.407843, 0.701961, 0.317647)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.317647, 0.541176, 0.313725)})
		FadeOut:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652973166"
		wait(tiempo)
	end
	wait(tiempo)
	Debounce = false
	script.Parent:WaitForChild("Take").Value = "False"
end)

	--Apagado
script.Parent.MouseButton1Click:Connect(function()
	if not Debounce then return end
	Debounce = true
	if StringValueObject.Value == "False" then
		Icon:TweenPosition(ClosePosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeIn = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(1, 0.537255, 0.537255)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.509804, 0.509804, 0.509804)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.529412, 0.313725, 0.313725)})
		FadeIn:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652972833"
		wait(tiempo)
	end
	wait(tiempo)
	Debounce = false
	script.Parent:WaitForChild("Take").Value = "True"
end)
1 Like

“if not Debounce then”
I think that’s backwards. Debounce starts false.

I’ve already tried and it doesn’t work either.

Oh you can’t have an event connected to two different functions. Those functions need to be merged with the proper use of elseifs or else’s.

It will execute no matter what, I think.

Try this script:

local Icon = script.Parent:WaitForChild("Icon")
local Button = script.Parent
local OpenPosition = UDim2.new(0.85, 0, 0.5, 0)
local ClosePosition = UDim2.new(0.15, 0, 0.5, 0)
local tiempo = 0.3
local Debounce = false
local TweenService = game:GetService("TweenService")
local Fire = game:GetService("ReplicatedStorage"):WaitForChild("ConfiguracionGeneral"):WaitForChild("JuegoConfg")
local time = 1
local GUISave = game:WaitForChild("ReplicatedStorage"):WaitForChild("GUI"):WaitForChild("FrameSave")
local StringValueObject = script.Parent:WaitForChild("Take")

-- es el de Encendido
script.Parent.MouseButton1Click:Connect(function()
	if not Debounce then return
	else
	Debounce = false
	if StringValueObject.Value == "True" then
		Icon:TweenPosition(OpenPosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeOut = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(0.501961, 1, 0.501961)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.407843, 0.701961, 0.317647)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.317647, 0.541176, 0.313725)})
		FadeOut:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652973166"
		wait(tiempo)
	end
	wait(tiempo)
	Debounce = false
	script.Parent:WaitForChild("Take").Value = "False"
	end	
end)

--Apagado
script.Parent.MouseButton1Click:Connect(function()
	if not Debounce then return
	else
	Debounce = false
	if StringValueObject.Value == "False" then
		Icon:TweenPosition(ClosePosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeIn = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(1, 0.537255, 0.537255)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.509804, 0.509804, 0.509804)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.529412, 0.313725, 0.313725)})
		FadeIn:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652972833"
		wait(tiempo)
	end
	wait(tiempo)
	Debounce = true
	script.Parent:WaitForChild("Take").Value = "True"
	end	
end)

If the script doesn’t work then,

Replace:

With: script.Parent.MouseButton1Down:Connect(function()

Everywhere you see:

Sometimes the function “MouseButton1Click” doesn’t work, so try “MouseButton1Down”

2 Likes

You don’t need to merge the two functions together.

If my last post didn’t work:

Just add 2 seperate debounces for the seperate functions.

Script/Example:

local Icon = script.Parent:WaitForChild("Icon")
local Button = script.Parent
local OpenPosition = UDim2.new(0.85, 0, 0.5, 0)
local ClosePosition = UDim2.new(0.15, 0, 0.5, 0)
local tiempo = 0.3
local Debounce = false
local Debounce2 = false
local TweenService = game:GetService("TweenService")
local Fire = game:GetService("ReplicatedStorage"):WaitForChild("ConfiguracionGeneral"):WaitForChild("JuegoConfg")
local time = 1
local GUISave = game:WaitForChild("ReplicatedStorage"):WaitForChild("GUI"):WaitForChild("FrameSave")
local StringValueObject = script.Parent:WaitForChild("Take")

-- es el de Encendido
script.Parent.MouseButton1Down:Connect(function()
	if not Debounce then return
	else
	Debounce = true
	if StringValueObject.Value == "True" then
		Icon:TweenPosition(OpenPosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeOut = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(0.501961, 1, 0.501961)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.407843, 0.701961, 0.317647)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.317647, 0.541176, 0.313725)})
		FadeOut:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652973166"
		wait(tiempo)
	end
	wait(tiempo)
	Debounce = false
	script.Parent:WaitForChild("Take").Value = "False"
	end
end)

--Apagado
script.Parent.MouseButton1Down:Connect(function()
	if not Debounce2 then return
	else
	Debounce2 = true
	if StringValueObject.Value == "False" then
		Icon:TweenPosition(ClosePosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeIn = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(1, 0.537255, 0.537255)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.509804, 0.509804, 0.509804)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.529412, 0.313725, 0.313725)})
		FadeIn:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652972833"
		wait(tiempo)
	end
	wait(tiempo)
	Debounce2 = false
	script.Parent:WaitForChild("Take").Value = "True"
	end
end)
1 Like

I appreciate your help but sadly it doesn’t work.

1 Like

(Deleted Message e0c204c2396-)

1 Like

I already tried with your previous posts.

1 Like

Oops. I forgot to edit one last thing. I just edited. Try my last post now.

1 Like

Ok. I keep forgetting to add the last things.

This should be the working script:

local Icon = script.Parent:WaitForChild("Icon")
local Button = script.Parent
local OpenPosition = UDim2.new(0.85, 0, 0.5, 0)
local ClosePosition = UDim2.new(0.15, 0, 0.5, 0)
local tiempo = 0.3
local Debounce = true
local Debounce2 = true
local TweenService = game:GetService("TweenService")
local Fire = game:GetService("ReplicatedStorage"):WaitForChild("ConfiguracionGeneral"):WaitForChild("JuegoConfg")
local time = 1
local GUISave = game:WaitForChild("ReplicatedStorage"):WaitForChild("GUI"):WaitForChild("FrameSave")
local StringValueObject = script.Parent:WaitForChild("Take")

-- es el de Encendido
script.Parent.MouseButton1Down:Connect(function()
	if not Debounce then 
	else
		Debounce = false
		if StringValueObject.Value == "True" then
			Icon:TweenPosition(OpenPosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
			local FadeOut = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(0.501961, 1, 0.501961)})
			local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.407843, 0.701961, 0.317647)})
			local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.317647, 0.541176, 0.313725)})
			FadeOut:Play()
			FadeInOut:Play()
			FadeInColor:Play()
			Icon.Image = "http://www.roblox.com/asset/?id=6652973166"
			wait(tiempo)
		end
		wait(tiempo)
		Debounce = true
		script.Parent:WaitForChild("Take").Value = "False"
	end
end)

--Apagado
script.Parent.MouseButton1Down:Connect(function()
	if not Debounce2 then
	else
		Debounce2 = false
		if StringValueObject.Value == "False" then
			Icon:TweenPosition(ClosePosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
			local FadeIn = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(1, 0.537255, 0.537255)})
			local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.509804, 0.509804, 0.509804)})
			local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.529412, 0.313725, 0.313725)})
			FadeIn:Play()
			FadeInOut:Play()
			FadeInColor:Play()
			Icon.Image = "http://www.roblox.com/asset/?id=6652972833"
			wait(tiempo)
		end
		wait(tiempo)
		Debounce2 = true
		script.Parent:WaitForChild("Take").Value = "True"
	end
end)
2 Likes

You are correct. I could have sworn that didn’t used to work, but what do I know anyways. It’s still arguably cleaner to have all of the related code wrapped up in a single event though. If anyone cares, here’s the code merged together. I find it much easier to read what is going on.

local Icon = script.Parent:WaitForChild("Icon")
local Button = script.Parent
local OpenPosition = UDim2.new(0.85, 0, 0.5, 0)
local ClosePosition = UDim2.new(0.15, 0, 0.5, 0)
local tiempo = 0.3
local Debounce = false
local TweenService = game:GetService("TweenService")
local Fire = game:GetService("ReplicatedStorage"):WaitForChild("ConfiguracionGeneral"):WaitForChild("JuegoConfg")
local time = 1
local GUISave = game:WaitForChild("ReplicatedStorage"):WaitForChild("GUI"):WaitForChild("FrameSave")
local StringValueObject = script.Parent:WaitForChild("Take")

script.Parent.MouseButton1Click:Connect(function()
	if Debounce then return end
	Debounce = true
	if StringValueObject.Value == "True" then
		Icon:TweenPosition(OpenPosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeOut = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(0.501961, 1, 0.501961)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.407843, 0.701961, 0.317647)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.317647, 0.541176, 0.313725)})
		FadeOut:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652973166"
		wait(tiempo)
		Debounce = false
		StringValueObject.Value = "False"
	elseif StringValueObject.Value == "False" then
		Icon:TweenPosition(ClosePosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeIn = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(1, 0.537255, 0.537255)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.509804, 0.509804, 0.509804)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.529412, 0.313725, 0.313725)})
		FadeIn:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652972833"
		wait(tiempo)
		Debounce = false
		StringValueObject.Value = "True"
	else
		warn("StringValueObject.Value is not \"True\" or \"False\"")
		wait(tiempo)
		Debounce = false
	end
end)
2 Likes

Understandable, have a nice day, and thank you =D

2 Likes