You could utilize a loop to make it more of an “automatic” process rather than needing to copy paste those lines of code and change the value each time.
Additionally, the lowest amount of time that you can use for “wait” is 0.03 seconds if I remember correctly [ which is achievable by just saying wait() ], so there’s no need to add wait(0.025).
Here’s an example code block utilizing a loop:
local Lighting = game:GetService("Lighting")
local function fadeOut()
local PremiumMenu = Lighting.PremiumMenu
PremiumMenu.Enabled = true
--[[
"50" is the starting number
"0" is the end number
"-5" is the increment
The loop below will make the effect start at 50 size, end at 0, and it'll
lower the size in increments of "-5" each time
--]]
for CurrentBlurSize = 50, 0, -5 do
wait()
PremiumMenu.Size = CurrentBlurSize
end
end
I would recommend switching over to TweenService as it’d make the blur fade out more smoothly.
I also stored Lighting and PremiumMenuBlur in variables to reduce repetition.
With these changes made, here’s how the script would look.
(the 0.25 in the TweenInfo is how long the tween lasts)
local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
local PremiumMenuBlur = Lighting.PremiumMenuBlur
local FadeOutTweenInfo = TweenInfo.new(
0.25,
Enum.EasingStyle.Linear
)
local FadeOutTween = TweenService:Create(PremiumMenuBlur, FadeOutTweenInfo, {Size = 0})
local function FadeOut()
PremiumMenuBlur.Enabled = true
PremiumMenuBlur.Size = 50
FadeOutTween:Play()
end
You’d have to change the starting size to 0 and the end size to be 50.
local FadeInTween = TweenService:Create(PremiumMenuBlur, FadeOutTweenInfo, {Size = 50})
local function FadeIn()
PremiumMenuBlur.Enabled = true
PremiumMenuBlur.Size = 0
FadeInTween:Play()
end
Sure! This is a script for opening/closing a GUI, and the blur fades in/out when you open/close the GUI.
local START_POSITION = UDim2.new(-0.5, 0,2, 0)
local GOAL_POSITION = UDim2.new(-0.5,0,-0.5,0)
local guiObject = script.Parent
local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
local PremiumMenuBlur = Lighting:WaitForChild("PremiumMenuBlur")
local FadeOutTweenInfo = TweenInfo.new(
0.25,
Enum.EasingStyle.Linear,
)
local function fadeOut()
local FadeOutTween = TweenService:Create(PremiumMenuBlur, FadeOutTweenInfo, {Size = 0})
PremiumMenuBlur.Enabled = true
PremiumMenuBlur.Size = 50
FadeOutTween:Play()
end
local function fadeIn()
local FadeInTween = TweenService:Create(PremiumMenuBlur, FadeOutTweenInfo, {Size = 50})
PremiumMenuBlur.Enabled = true
PremiumMenuBlur.Size = 0
FadeInTween:Play()
end
local function callback(state)
if state == Enum.TweenStatus.Completed then
-- Yay
elseif state == Enum.TweenStatus.Canceled then
-- :(
end
end
-- Initialize the GuiObject position, then start the tween:
guiObject.Position = START_POSITION
script.Parent.Parent.TopBarModifier.RightFrame.openWithPremium.MouseButton1Click:Connect(function()
if guiObject.Position == START_POSITION then
fadeIn()
local willPlay = guiObject:TweenPosition(
GOAL_POSITION, -- Final position the tween should reach
Enum.EasingDirection.Out, -- Direction of the easing
Enum.EasingStyle.Sine, -- Kind of easing to apply
0.75, -- Duration of the tween in seconds
true, -- Whether in-progress tweens are interrupted
callback -- Function to be callled when on completion/cancelation
)
if willPlay then
-- It will play...
else
-- No play :(
end
else
local willPlay = guiObject:TweenPosition(
START_POSITION, -- Final position the tween should reach
Enum.EasingDirection.In, -- Direction of the easing
Enum.EasingStyle.Sine, -- Kind of easing to apply
0.75, -- Duration of the tween in seconds
true, -- Whether in-progress tweens are interrupted
callback -- Function to be callled when on completion/cancelation
)
wait(0.75)
fadeOut()
if willPlay then
-- It will play...
else
-- No play :(
end
end
end)
Sorry about that, I accidentally left the comma there when I was writing the script. I’ll edit my solution so anyone who may find this topic in the future and use that code doesn’t run into an error.
local premiumMenu = game:GetService("Lightning").PremiumMenu
premiumMenu.Enabled = true
for blurSize = 50, 0, -5 do
premiumMenu.Size = blurSize
wait(0.025)
end