[LocalScript] Blur background inside "esc" menu

This is a localscript that blurs the screen of the player and disables saturation while the player is in the esc menu, this is how it works.

--CODED BY V1SIONUSE--
--PUT IN STARTERGUI--
--CREATE A "COLORCORRECTION" EFFECT IN LIGHTING FIRST--

local GuiService = game:GetService("GuiService")
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")

repeat
    wait()
until workspace.CurrentCamera

local Camera = workspace.CurrentCamera

local originalSaturation = Lighting.ColorCorrection.Saturation

GuiService.MenuOpened:Connect(function()
    local blur = Instance.new("BlurEffect")
    blur.Size = 0 -- Start with no blur
    blur.Parent = Camera

    local tweenInfo = TweenInfo.new(0.5) -- Set the duration of the tween (in seconds)
    local tween = TweenService:Create(blur, tweenInfo, { Size = 20 }) -- Tween the blur size from 0 to 20

    tween:Play() -- Start the tween

    local saturationTween = TweenService:Create(Lighting.ColorCorrection, tweenInfo, { Saturation = -1 }) -- Tween the saturation from its original value to -1
    saturationTween:Play() -- Start the saturation tween

    GuiService.MenuClosed:Connect(function()
        local reverseTween = TweenService:Create(blur, tweenInfo, { Size = 0 }) -- Tween the blur size from 20 back to 0
        reverseTween:Play() -- Start the reverse tween

        reverseTween.Completed:Connect(function()
            blur:Destroy() -- Destroy the blur effect once the reverse tween is completed

            local reverseSaturationTween = TweenService:Create(Lighting.ColorCorrection, tweenInfo, { Saturation = originalSaturation }) -- Tween the saturation back to its original value
            reverseSaturationTween:Play() -- Start the reverse saturation tween
        end)
    end)
end)
23 Likes
GuiService.MenuClosed:Connect(function()

This line will lead to loads of connections being made you should switch it to :Once instead of :Connect or take the line out of the MenuOpened connection so that only 1 connection is made

Also minor performance thing but there’s no need to create and destroy the blur objects / tweens every time, you can just make them once at the start of the script and reuse them

6 Likes

I would say move that out of the function entirely to avoid any possible memory altogether.

4 Likes

Thanks for providing this script! There are some functional issues with it, though, as others have noted. I made a small update to the script to fix a few of these issues:

-- written by V1SIONUSE
-- updated by AverageLua

local GuiService = game:GetService("GuiService")
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")

local ColorCorrectionEffect = Instance.new("ColorCorrectionEffect", Lighting)
local BlurEffect = Instance.new("BlurEffect", Lighting)
BlurEffect.Size = 0

local MenuEffectTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear)
local BlurEffectSize = 20
local ColorCorrectionSaturation = -1

local function MenuOpened()
	TweenService:Create(BlurEffect, MenuEffectTweenInfo, {
		Size = BlurEffectSize
	}):Play()

	TweenService:Create(ColorCorrectionEffect, MenuEffectTweenInfo, {
		Saturation = ColorCorrectionSaturation
	}):Play()
end

local function MenuClosed()
	TweenService:Create(BlurEffect, MenuEffectTweenInfo, {
		Size = 0
	}):Play()

	TweenService:Create(ColorCorrectionEffect, MenuEffectTweenInfo, {
		Saturation = 0
	}):Play()
end

GuiService.MenuOpened:Connect(MenuOpened)
GuiService.MenuClosed:Connect(MenuClosed)

(place this in a LocalScript within StarterPlayerScripts!)

Since it creates them on its own, this version doesn’t require any objects to be added to the Lighting service. Additionally, it prevents any potential memory leakage associated with GuiService event connections.

7 Likes

something like this?

--CODED BY V1SIONUSE--
--PUT IN STARTERGUI--
--CREATE A "COLORCORRECTION" EFFECT IN LIGHTING FIRST--

local GuiService = game:GetService("GuiService")
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")

repeat
	wait()
until workspace.CurrentCamera

local Camera = workspace.CurrentCamera
local originalSaturation = Lighting.ColorCorrection.Saturation

-- Create the blur effect once at the start
local blur = Instance.new("BlurEffect")
blur.Size = 0 -- Start with no blur
blur.Parent = Camera

-- Create the tweens once at the start
local tweenInfo = TweenInfo.new(0.5) -- Set the duration of the tween (in seconds)
local tween = TweenService:Create(blur, tweenInfo, { Size = 20 }) -- Tween the blur size from 0 to 20
local reverseTween = TweenService:Create(blur, tweenInfo, { Size = 0 }) -- Tween the blur size from 20 back to 0

GuiService.MenuOpened:Connect(function()
	tween:Play() -- Start the blur tween
	local saturationTween = TweenService:Create(Lighting.ColorCorrection, tweenInfo, { Saturation = -1 }) -- Tween the saturation from its original value to -1
	saturationTween:Play() -- Start the saturation tween

	GuiService.MenuClosed:Once(function()
		reverseTween:Play() -- Start the reverse blur tween

		reverseTween.Completed:Connect(function()
			local reverseSaturationTween = TweenService:Create(Lighting.ColorCorrection, tweenInfo, { Saturation = originalSaturation }) -- Tween the saturation back to its original value
			reverseSaturationTween:Play() -- Start the reverse saturation tween
		end)
	end)
end)
1 Like

Hi! I used a colorcorrection cause if a game has modified the saturation of their game with a colorcorrection, it has to keep that value when going out of the menu

1 Like

Here is a better script which changed unnecessary connections:

--CODED BY V1SIONUSE--
--PUT IN STARTERGUI--
--CREATE A "COLORCORRECTION" EFFECT IN LIGHTING FIRST--

local GuiService = game:GetService("GuiService")
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")

local Camera = workspace.CurrentCamera or workspace:GetPropertyChangedSignal("CurrentCamera"):Wait()

local originalSaturation = Lighting.ColorCorrection.Saturation

GuiService.MenuOpened:Connect(function()
	local blur = Instance.new("BlurEffect")
	blur.Size = 0 -- Start with no blur
	blur.Parent = Camera

	local tweenInfo = TweenInfo.new(0.5) -- Set the duration of the tween (in seconds)
	local tween = TweenService:Create(blur, tweenInfo, { Size = 20 }) -- Tween the blur size from 0 to 20

	tween:Play() -- Start the tween

	local saturationTween = TweenService:Create(Lighting.ColorCorrection, tweenInfo, { Saturation = -1 }) -- Tween the saturation from its original value to -1
	saturationTween:Play() -- Start the saturation tween

	GuiService.MenuClosed:Once(function()
		local reverseTween = TweenService:Create(blur, tweenInfo, { Size = 0 }) -- Tween the blur size from 20 back to 0
		reverseTween:Play() -- Start the reverse tween

		reverseTween.Completed:Once(function()
			blur:Destroy() -- Destroy the blur effect once the reverse tween is completed

			local reverseSaturationTween = TweenService:Create(Lighting.ColorCorrection, tweenInfo, { Saturation = originalSaturation }) -- Tween the saturation back to its original value
			reverseSaturationTween:Play() -- Start the reverse saturation tween
		end)
	end)
end)
3 Likes

How? It makes one connection? And then when a script is destroyed (when the character dies) the connections also get disconnected. So its not like its duplicating scripts and their connections.

What if the user opens, closes and then reopens the menu? It will just stop working?

However I would suggest placing it in StarterPlayerScripts instead since what if the character hasnt loaded in an is in a menu? The script would not have fired and the blur effect wouldn’t work.

I agree with this although it is a very minor improvement

1 Like

Whenever the menu is opened it creates a brand new menu closed connection

It makes a new connection each time the menu is opened so no (also tried it in studio and it does work)

1 Like

No, there are connections inside connections, that is the issue


No, they only mean switching the connections inside connections to once.

1 Like

Sorry I didn’t read the entire script my apologises

2 Likes