Issue with BlurEffect changing size value from Localscript

Hello, so currently I’m trying to finalize my UserInterface for a game I’ve been working on and one of the features that has’t to be finished is the return to menu, which can be activated by either double-tapping the “M” key on a laptop/PC or pressing a button on mobile. (Xbox not supported as of right now). Now the base of the function works, however, an issue I’m having is activating the blur effect. I’ve designated two separate functions for this called EnableBlur() and DisableBlur(), however when returning to the menu, it seems like the EnableBlur function just fails to work even though it works on first join.

Here’s the code;

local function DisableBlur()
	for i = 1,BlurEffect.Size do
		wait(0.1)
		BlurEffect.Size = BlurEffect.Size - 1
	end
	BlurEffect.Enabled = false
	return false
end

local function EnableBlur()
	BlurEffect.Enabled = true
	for i = 1,BlurEffect.Size do
		wait(0.1)
		BlurEffect.Size = BlurEffect.Size + 1
	end
	return true
end

local function CloseCurrentTab()
	if CurrentTab ~= nil then
		CurrentTab:TweenPosition(MenuConfig.Tab_ClosePos,Enum.EasingDirection.Out,Enum.EasingStyle.Linear,MenuConfig.SlideTime,false,function()
			CurrentTab:TweenPosition(MenuConfig.Tab_HiddenPos,Enum.EasingDirection.Out,Enum.EasingStyle.Linear,0,false,function()	
				CurrentTab.Visible = false
				return false
			end)
		end)
	end
end

local function EnableMenu()
	
	if MenuEnabled then return false end
	
	local LocalCamera = Workspace:FindFirstChild('Camera')
	
	if not MenuConfig.CameraPart then return false end
	
	
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,false)
	EnableBlur()
	
	
	LocalCamera.CameraType = "Scriptable"
	LocalCamera.CameraSubject = MenuConfig.CameraPart
	LocalCamera.CFrame = MenuConfig.CameraPart.CFrame

	MainMenu.Visible = true
	MenuEnabled = true
		
	TitleDisplay.Title.Text = MenuConfig.GameTitle
	MainMenu:TweenPosition(MenuConfig.RevealedPosition,Enum.EasingDirection.Out,Enum.EasingStyle.Linear,MenuConfig.SlideTime)
	
end

local function CloseMenu()
	
	CloseCurrentTab()
	MainMenu:TweenPosition(UDim2.new(-0.077, 0,0.538, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Linear,0.5,false,function()
		MainMenu.Visible = false
		MenuEnabled = false
				
		local LocalCamera = Workspace:FindFirstChild('Camera')
				
		LocalCamera.CameraType = "Custom"
		LocalCamera.CameraSubject = LocalCharacter.Head
		
		DisableBlur()
		
		BlurEffect.Enabled = false
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,true)
		
		ToggleHUD()
	end)	
end

Here’s a gif of it;

https://gyazo.com/52dfa08836f7cb8059007111d6e312d6


The gif above shows the menu opening + blur on join, and then the menu opening + blur via double-tapping the “M” key.

Any help trying to solve this issue is much appriecated, thanks!

EnableBlur() fails the second time around since your for loop depends on BlurEffect.Size to change the blur.

local function EnableBlur()
	BlurEffect.Enabled = true
	for i = 1,BlurEffect.Size do
		wait(0.1)
		BlurEffect.Size = BlurEffect.Size + 1
	end
	return true
end

Breaking down the code line by line we see that

  1. The script enables the BlurEffect, but that doesn’t matter since BlurEffect.Size is 0
  2. Since DisableBlur() had decreased BlurEffect.Size to 0, the line is effectively: for i = 1, 0 do. Since 1 > 0, the for loop doesn’t run at all.
  3. Skipped
  4. Skipped
  5. Skipped
  6. Script returns true

Thus the blur isn’t enabled the second time.

This can be fixed by having a hard coded value for BlurEffect.Size when it is enabled as such:

local function EnableBlur()
	BlurEffect.Enabled = true
	for i = 1, 5 do -- BlurEffect.Size will change to 5 at the end of the loop
		wait(0.1)
		BlurEffect.Size = BlurEffect.Size + 1
	end
	return true
end

Hope this solved your problem, feel free to point out any mistakes or reply for any questions

2 Likes