Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Setting up the module
- local module = {}
- -- Getting the "TweenService" from "game"
- local tweenService = game:GetService("TweenService")
- -- Getting the "ScreenGui" object from the script parent
- local screenGui = script.Parent:WaitForChild("ScreenGui")
- -- Setting the speed of the window opening and closing animation
- local OpenSpeed = 0.8
- local CloseSpeed = 0.2
- -- Setting styles and directions for window opening and closing animations
- local OpenEasingStyle = Enum.EasingStyle.Back
- local OpenEasingDirection = Enum.EasingDirection.Out
- local ClosingEasingStyle = Enum.EasingStyle.Sine
- local ClosingEasingDirection = Enum.EasingDirection.Out
- -- Function for getting a window (frame) by its name
- function module.GetFrame(frameName)
- -- Retrieve all descendants of "ScreenGui"
- local frames = screenGui:GetDescendants()
- -- Variable for the window (frame)
- local frame = nil
- -- Searching descendants to find a window with the given name
- for i, item in pairs(frames) do
- if item.Name == frameName then
- frame = item
- end
- end
- -- Return the found window
- return frame
- end
- -- Function for opening a window
- function module.OpenFrame(frameName)
- -- Getting the window (frame) from the function "module.GetFrame"
- local frame = module.GetFrame(frameName)
- -- If the window is found
- if frame then
- -- Getting the normal size of the window
- local normalSize = frame.Size
- -- Setting the window size to very small
- frame.Size = UDim2.fromScale(0, 0)
- -- Waiting for closing to complete
- task.wait(CloseSpeed + 0.1)
- -- Setting the visibility of the window to true
- frame.Visible = true
- -- Creating the window opening animation
- local openTween = tweenService:Create(
- frame,
- TweenInfo.new(
- OpenSpeed,
- OpenEasingStyle,
- OpenEasingDirection),
- {
- Size = normalSize
- }
- )
- -- Playing the opening animation
- openTween:Play()
- end
- end
- -- The module.CloseFrame function is used to close a window (frame)
- function module.CloseFrame(frameName)
- -- Getting the frame object based on the name
- local frame = module.GetFrame(frameName)
- -- Checking if the frame exists
- if frame then
- -- Storing the current frame size
- local normalSize = frame.Size
- -- Creating an animation to decrease the frame size to 0
- local closeTween = tweenService:Create(
- frame,
- TweenInfo.new(
- CloseSpeed,
- ClosingEasingStyle,
- ClosingEasingDirection),
- {
- Size = UDim2.fromScale(0, 0)
- }
- )
- -- Start of animation
- closeTween:Play()
- -- After the animation ends, hiding the frame and returning it to its original size
- closeTween.Completed:Connect(function()
- frame.Visible = false
- frame.Size = normalSize
- end)
- end
- end
- -- Loop through all descendants of the screenGui object
- for _, v in pairs(screenGui:GetDescendants()) do
- -- If the object is of type GuiButton (button)
- if v:IsA("GuiButton") then
- -- If the button has a child named "Opens"
- if v:FindFirstChild("Opens") then
- -- If the "Opens" property is not empty
- if v:FindFirstChild("Opens").Value ~= nil then
- -- When the button is clicked, call the module.OpenFrame function
- -- with the frame name parameter to open
- v.MouseButton1Click:Connect(function()
- module.OpenFrame(v:FindFirstChild("Opens").Value.Name)
- end)
- end
- end
- -- If the button has a child named "Closes"
- if v:FindFirstChild("Closes") then
- -- If the "Closes" property is not empty
- if v:FindFirstChild("Closes").Value ~= nil then
- -- When the button is clicked, call the module.CloseFrame function
- -- with the frame name parameter to close
- 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