Advertisement
coding_giants

l2 module script comment

Mar 13th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. -- Setting up the module
  2. local module = {}
  3. -- Getting the "TweenService" from "game"
  4. local tweenService = game:GetService("TweenService")
  5. -- Getting the "ScreenGui" object from the script parent
  6. local screenGui = script.Parent:WaitForChild("ScreenGui")
  7. -- Setting the speed of the window opening and closing animation
  8. local OpenSpeed = 0.8
  9. local CloseSpeed = 0.2
  10.  
  11.  
  12. -- Setting styles and directions for window opening and closing animations
  13. local OpenEasingStyle = Enum.EasingStyle.Back
  14. local OpenEasingDirection = Enum.EasingDirection.Out
  15.  
  16.  
  17. local ClosingEasingStyle = Enum.EasingStyle.Sine
  18. local ClosingEasingDirection = Enum.EasingDirection.Out
  19.  
  20.  
  21.  
  22.  
  23. -- Function for getting a window (frame) by its name
  24. function module.GetFrame(frameName)
  25. -- Retrieve all descendants of "ScreenGui"
  26. local frames = screenGui:GetDescendants()
  27. -- Variable for the window (frame)
  28. local frame = nil
  29. -- Searching descendants to find a window with the given name
  30. for i, item in pairs(frames) do
  31. if item.Name == frameName then
  32. frame = item
  33. end
  34. end
  35. -- Return the found window
  36. return frame
  37. end
  38.  
  39.  
  40. -- Function for opening a window
  41. function module.OpenFrame(frameName)
  42. -- Getting the window (frame) from the function "module.GetFrame"
  43. local frame = module.GetFrame(frameName)
  44. -- If the window is found
  45. if frame then
  46. -- Getting the normal size of the window
  47. local normalSize = frame.Size
  48. -- Setting the window size to very small
  49. frame.Size = UDim2.fromScale(0, 0)
  50. -- Waiting for closing to complete
  51. task.wait(CloseSpeed + 0.1)
  52. -- Setting the visibility of the window to true
  53. frame.Visible = true
  54. -- Creating the window opening animation
  55. local openTween = tweenService:Create(
  56. frame,
  57. TweenInfo.new(
  58. OpenSpeed,
  59. OpenEasingStyle,
  60. OpenEasingDirection),
  61. {
  62. Size = normalSize
  63. }
  64. )
  65. -- Playing the opening animation
  66. openTween:Play()
  67. end
  68. end
  69.  
  70. -- The module.CloseFrame function is used to close a window (frame)
  71. function module.CloseFrame(frameName)
  72. -- Getting the frame object based on the name
  73. local frame = module.GetFrame(frameName)
  74.  
  75. -- Checking if the frame exists
  76. if frame then
  77. -- Storing the current frame size
  78. local normalSize = frame.Size
  79. -- Creating an animation to decrease the frame size to 0
  80. local closeTween = tweenService:Create(
  81. frame,
  82. TweenInfo.new(
  83. CloseSpeed,
  84. ClosingEasingStyle,
  85. ClosingEasingDirection),
  86. {
  87. Size = UDim2.fromScale(0, 0)
  88. }
  89. )
  90. -- Start of animation
  91. closeTween:Play()
  92. -- After the animation ends, hiding the frame and returning it to its original size
  93. closeTween.Completed:Connect(function()
  94. frame.Visible = false
  95. frame.Size = normalSize
  96. end)
  97. end
  98. end
  99.  
  100.  
  101. -- Loop through all descendants of the screenGui object
  102. for _, v in pairs(screenGui:GetDescendants()) do
  103. -- If the object is of type GuiButton (button)
  104. if v:IsA("GuiButton") then
  105. -- If the button has a child named "Opens"
  106. if v:FindFirstChild("Opens") then
  107. -- If the "Opens" property is not empty
  108. if v:FindFirstChild("Opens").Value ~= nil then
  109. -- When the button is clicked, call the module.OpenFrame function
  110. -- with the frame name parameter to open
  111. v.MouseButton1Click:Connect(function()
  112. module.OpenFrame(v:FindFirstChild("Opens").Value.Name)
  113. end)
  114. end
  115. end
  116. -- If the button has a child named "Closes"
  117. if v:FindFirstChild("Closes") then
  118. -- If the "Closes" property is not empty
  119. if v:FindFirstChild("Closes").Value ~= nil then
  120. -- When the button is clicked, call the module.CloseFrame function
  121. -- with the frame name parameter to close
  122. v.MouseButton1Click:Connect(function()
  123. module.CloseFrame(v:FindFirstChild("Closes").Value.Name)
  124. end)
  125. end
  126. end
  127. end
  128. end
  129.  
  130.  
  131. return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement