So I have a container which contains the frames in the Center and it plays a Blur and FOV
Tween when they become visible and not visible. Im trying to make it so that only one CenterFrame
is Visible . This is what the code and the explorer looks like.
for _, v in pairs(centerContainer:GetChildren()) do
if v:IsA("Frame") then
v.Changed:Connect(function()
if v.Visible then
if not blur.Enabled then
blur.Enabled = true
end
local fadeBlur = tweenService:Create(blur, blurInfo, {Size = 16})
local fadeFOV = tweenService:Create(camera, blurInfo, {FieldOfView = 55})
fadeBlur:Play()
fadeFOV:Play()
task.wait(.2)
if not blur.Enabled then
blur.Enabled = true
end
else
local fadeBlur = tweenService:Create(blur, blurInfo, {Size = 0})
local fadeFOV = tweenService:Create(camera, blurInfo, {FieldOfView = 80})
if v.Visible then
return
end
fadeBlur:Play()
fadeFOV:Play()
fadeFOV.Completed:Wait()
blur.Enabled = false
end
end)
end
end
settingsButton.MouseButton1Click:Connect(function()
settingsFrame.Visible = not settingsFrame.Visible
for _, v in pairs(centerContainer:GetChildren()) do
if v:IsA("Frame") and v.Name ~= 'SettingsFrame' then
v.Visible = false
end
end
end)
bottomContainer:WaitForChild("oro").MouseButton1Click:Connect(function()
centerContainer:WaitForChild("oroFrame").Visible = not centerContainer.oroFrame.Visible
for _, v in pairs(centerContainer:GetChildren()) do
if v:IsA("Frame") and v.Name ~= 'oroFrame' then
v.Visible = false
end
end
end)
I’m basically trying to make it like Pet Simulator X (i guess), where you can only open one Frame at a time.
If there’s an efficient way of doing this, please inform me.
One problem I have is that when opening a Frame and then opening another Frame the Blur and FOV Tweens start bugging out.
I’m not a UI person but I feel like you could just do local functions to close the other tabs whenever you open one tab
local FocusedTab -- empty for now, make sure to make it nil when you close all tabs!
local function CloseOthers()
for _, v in pairs(centerContainer:GetChildren()) do
if v:IsA("Frame") and v.Name ~= FocusedTab then
v.Visible = false
if v.Name == FocusedTab then --incase the focused tab is invisible.. which it should be
v.Visible = true
end
end
end
end
settingsButton.MouseButton1Click:Connect(function()
FocusedTab = "SettingsFrame" -- sets this to be the priority tab, wont close
-- you dont even have to make it visible here because the local function should handle it :)
CloseOthers()
end)
I haven’t tested this but hope it helps!
Oh and for the tweens just check if its already open by having a bool variable that sets to true if its open and false to when it closes, then play the tween once they open it and elseif they close it
local open = false -- because it should be closed by default
local function tweens()
if open then
if not blur.Enabled then
blur.Enabled = true
end
local fadeBlur = tweenService:Create(blur, blurInfo, {Size = 16})
local fadeFOV = tweenService:Create(camera, blurInfo, {FieldOfView = 55})
fadeBlur:Play()
fadeFOV:Play()
task.wait(.2)
if not blur.Enabled then
blur.Enabled = true
end
elseif not open then
local fadeBlur = tweenService:Create(blur, blurInfo, {Size = 0})
local fadeFOV = tweenService:Create(camera, blurInfo, {FieldOfView = 80})
if v.Visible then
return
end
fadeBlur:Play()
fadeFOV:Play()
fadeFOV.Completed:Wait()
blur.Enabled = false
end
end
end
end
settingsButton.MouseButton1Click:Connect(function()
open = true
tweens()
FocusedTab = "SettingsFrame" -- sets this to be the priority tab, wont close
-- you dont even have to make it visible here because the local function should handle it :)
CloseOthers()
end)
Havent tested this either! but hopefully it’ll help
So I took your code and modified it a bit to make it function. If anyone sees this and needs help I’ll post the script:
local focusedTab
local open = false -- because it should be closed by default
local function TweenBlur() --THIS ONE IS NOT NECESSARY ITS ONLY FOR ANIMATIONS
if open then
if not blur.Enabled then
blur.Enabled = true
end
local fadeBlur = tweenService:Create(blur, blurInfo, {Size = 16})
local fadeFOV = tweenService:Create(camera, blurInfo, {FieldOfView = 55})
fadeBlur:Play()
fadeFOV:Play()
elseif not open then
local fadeBlur = tweenService:Create(blur, blurInfo, {Size = 0})
local fadeFOV = tweenService:Create(camera, blurInfo, {FieldOfView = 80})
fadeBlur:Play()
fadeFOV:Play()
fadeFOV.Completed:Wait()
blur.Enabled = false
end
end
local function CloseOthers(open)
for _, v in pairs(centerContainer:GetChildren()) do
if v:IsA("Frame") then
v.Visible = false
if v.Name == focusedTab and open then --incase the focused tab is invisible.. which it should be
v.Visible = true
else
v.Visible = false
end
end
end
end
This one is for the button:
settingsButton.MouseButton1Click:Connect(function()
open = not open
if focusedTab ~= "SettingsFrame" then
open = true
end
focusedTab = "SettingsFrame"
print(open)
CloseOthers(open)
TweenBlur()
end)