Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- local tweenService = game:GetService("TweenService")
- local screenGui = script.Parent:WaitForChild("ScreenGui")
- local OpenSpeed = 0.8
- local CloseSpeed = 0.2
- local OpenEasingStyle = Enum.EasingStyle.Back
- local OpenEasingDirection = Enum.EasingDirection.Out
- local ClosingEasingStyle = Enum.EasingStyle.Sine
- local ClosingEasingDirection = Enum.EasingDirection.Out
- function module.GetFrame(frameName)
- local frames = screenGui:GetDescendants()
- local frame = nil
- for i, item in pairs(frames) do
- if item.Name == frameName then
- frame = item
- end
- end
- return frame
- end
- function module.OpenFrame(frameName)
- local frame = module.GetFrame(frameName)
- if frame then
- local normalSize = frame.Size
- frame.Size = UDim2.fromScale(0, 0)
- task.wait(CloseSpeed + 0.1)
- frame.Visible = true
- local openTween = tweenService:Create(
- frame,
- TweenInfo.new(
- OpenSpeed,
- OpenEasingStyle,
- OpenEasingDirection),
- {
- Size = normalSize
- }
- )
- openTween:Play()
- end
- end
- function module.CloseFrame(frameName)
- local frame = module.GetFrame(frameName)
- if frame then
- local normalSize = frame.Size
- local closeTween = tweenService:Create(
- frame,
- TweenInfo.new(
- CloseSpeed,
- ClosingEasingStyle,
- ClosingEasingDirection),
- {
- Size = UDim2.fromScale(0, 0)
- }
- )
- closeTween:Play()
- closeTween.Completed:Connect(function()
- frame.Visible = false
- frame.Size = normalSize
- end)
- end
- end
- for _, v in pairs(screenGui:GetDescendants()) do
- if v:IsA("GuiButton") then
- if v:FindFirstChild("Opens") then
- if v:FindFirstChild("Opens").Value ~= nil then
- v.MouseButton1Click:Connect(function()
- module.OpenFrame(v:FindFirstChild("Opens").Value.Name)
- end)
- end
- end
- if v:FindFirstChild("Closes") then
- if v:FindFirstChild("Closes").Value ~= nil then
- v.MouseButton1Click:Connect(function()
- module.CloseFrame(v:FindFirstChild("Closes").Value.Name)
- end)
- end
- end
- end
- end
- return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement