function UIController:OpenUI(Name)
local ui = PlayerGui.Main:FindFirstChild(Name)
print(ui)
if not ui then warn("FAILED TO OPEN / CLOSE UI") return end
isProcess = true
if canOpen and isCompleted then
print("a")
canOpen = false
isCompleted = false
local FinalPosition = UDim2.fromScale(0.5,0.5)
local FinalSize = UIController.OriginalSizes.GUIS[Name]
local tweenPos = TweenService:Create(ui.Canvas, TweenInfo.new(0.4), {Position = FinalPosition})
local tweenSize = TweenService:Create(ui.Canvas, TweenInfo.new(0.4), {Size = FinalSize})
ui.Enabled = true
tweenPos:Play()
tweenSize:Play()
SoundController:PlaySound("FrameOpen",1)
tweenPos.Completed:Wait()
isCompleted = true
elseif isCompleted then
canOpen = true
isCompleted = false
local FinalPosition = UDim2.fromScale(0.5,0.65)
local FinalSize = UDim2.fromScale(0,0)
local tweenPos = TweenService:Create(ui.Canvas, TweenInfo.new(0.4), {Position = FinalPosition})
local tweenSize = TweenService:Create(ui.Canvas, TweenInfo.new(0.4), {Size = FinalSize})
tweenPos:Play()
tweenSize:Play()
SoundController:PlaySound("FrameOpen",1)
tweenPos.Completed:Wait()
ui.Enabled = false
end
isProcess = false
end
local function setUi(ui, open: boolean, fieldOfView, finalPosition, finalSize)
canOpen = not open
isCompleted = false
local tweenPos = TweenService:Create(ui.Canvas, TweenInfo.new(0.25), {Position = finalPosition})
local tweenSize = TweenService:Create(ui.Canvas, TweenInfo.new(0.25), {Size = finalSize})
local newField = TweenService:Create(game.Workspace.CurrentCamera, TweenInfos.Blur, {FieldOfView = fieldOfView})
if open then
ui.Enabled = true
end
tweenPos:Play()
tweenSize:Play()
newField:Play()
SoundController:PlaySound("FrameOpen",1)
tweenPos.Completed:Wait()
if not open then
ui.Enabled = false
end
isCompleted = true
end
local function openUI(Name)
local ui = PlayerGui.Main:FindFirstChild(Name)
print(ui)
if not ui then warn("FAILED TO OPEN / CLOSE UI") return end
isProcess = true
if canOpen and isCompleted then
local FinalPosition = UDim2.fromScale(0.5,0.5)
local FinalSize = UIController.OriginalSizes.GUIS[Name]
setUi(ui, true, 90, FinalPosition, FinalSize)
elseif isCompleted then
canOpen = true
isCompleted = false
local FinalPosition = UDim2.fromScale(0.5,0.65)
local FinalSize = UDim2.fromScale(0,0)
setUi(ui, false, 70, FinalPosition, FinalSize)
end
isProcess = false
end
Also use workspace
instead of game.Workspace
.