How can I improve my Menu_Closed/Opened blur effect

Hello, Recently I and a friend have been working on an open source Blur effect that enables when the Menu is opened/closed, and I was wondering if anyone could give me feedback, I have been having some errors in this script as well, this includes when the player spams the Menu, sometimes the blur does not show, I would like it if someone could tell me how to fix it, I already have a debounce in place.

local Lighting = game:GetService("Lighting")
local Blur = Lighting.Blur
local TweenService = game:GetService("TweenService")

local isMenuOpen = false
local isTweening = false
local blurTween


local function toggleBlur(enabled)

	if isTweening then
		return
	end

	isTweening = true
	
	if blurTween then
		blurTween:Cancel()
	end

	if enabled then
		Blur.Enabled = true
		blurTween = TweenService:Create(Blur, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = 20})
		blurTween:Play()
	else

		blurTween = TweenService:Create(Blur, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = 0})
		blurTween:Play()
		blurTween.Completed:Wait() 
		Blur.Enabled = false
	end


	isTweening = false
end


GuiService.MenuOpened:Connect(function()
	if not isMenuOpen then 
		isMenuOpen = true
		toggleBlur(true)
	end
end)


GuiService.MenuClosed:Connect(function()
	if isMenuOpen then 
		isMenuOpen = false
		toggleBlur(false)
	end
end)
1 Like

I would avoid returning if the tween is ongoing. This code is going to skip doing anything if a previous tween is active, regardless of whether it was blurring or unblurring:

if isTweening then
		return
end

If you can abort the previous tween instead, that would be better.

Having a single Boolean to debounce two different actions look like asking for trouble. :slight_smile:

1 Like

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