Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --!nocheck
- local Notification = {}
- -----<| SERVICES |>-----
- local TweenService = game:GetService("TweenService")
- -----<| PLAYER |>-----
- local player: Player = game:GetService("Players").LocalPlayer
- local playerGui: PlayerGui = player:WaitForChild("PlayerGui")
- -----<| GUI |>-----
- local UI: ScreenGui = script:WaitForChild("Notification")
- -----<| NOTIFICATION TYPE |>-----
- type Notification = {
- Title: string,
- Description: string,
- Button1: boolean,
- Button2: boolean,
- Callback1: any,
- Callback2: any
- }
- function Notification:Notify(args: Notification)
- assert(type(args.Callback1) == "function", "![[ Callback1 must be a function ]]!")
- assert(type(args.Callback2) == "function", "![[ Callback2 must be a function ]]!")
- -----<| DUPLICATE GUI |>-----
- local NewUI: ScreenGui = UI:clone()
- local Menu: Frame = NewUI:WaitForChild("Menu")
- local Background: Frame, Exit: ImageButton, Title: TextLabel = Menu:WaitForChild("Background"), Menu:WaitForChild("Exit"), Menu:WaitForChild("Title")
- local Buttons: Frame, Description: TextLabel = Background:WaitForChild("Buttons"), Background:WaitForChild("Description")
- local Okay: Folder, YesNo: Folder = Buttons:WaitForChild("Okay"), Buttons:WaitForChild("YesNo")
- local OkayButton: TextButton = Okay:WaitForChild("Okay")
- local YesButton: TextButton, NoButton: TextButton = YesNo:WaitForChild("Yes"), YesNo:WaitForChild("No")
- NewUI.Parent = playerGui
- -----<| VARIABLES |>-----
- local buttons =
- {
- ["Okay"] =
- {
- ["Button"] = OkayButton,
- ["Callback"] = args.Callback1
- },
- ["Yes"] =
- {
- ["Button"] = YesButton,
- ["Callback"] = args.Callback1
- },
- ["No"] =
- {
- ["Button"] = NoButton,
- ["Callback"] = args.Callback2
- },
- }
- -----<| FUNCTIONS |>-----
- local function CloseUI(close: boolean)
- local properties = (close) and {Position = UDim2.new(0.5, 0, 1.2, 0)} or {Position = UDim2.new(0.5, 0, 0.35, 0)}
- local info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
- local tween = TweenService:Create(Menu, info, properties)
- tween:Play()
- tween.Completed:Connect(function()
- if close then
- NewUI:Destroy()
- end
- end)
- end
- local function SetInfo()
- Title.Text = args.Title
- Description.Text = args.Description
- end
- local function SetDraggable(draggable: boolean)
- Menu.Active = draggable
- Menu.Draggable = draggable
- end
- local function ShowButtons()
- OkayButton.Visible = (args.Button1 and not args.Button2) and true or false
- YesButton.Visible, NoButton.Visible = (args.Button1 and args.Button2) and true or false, (args.Button1 and args.Button2) and true or false
- end
- local function OnButtonsClick()
- for _, button in pairs(buttons) do
- button["Button"].MouseButton1Click:Connect(function()
- CloseUI(true)
- button["Callback"]()
- end)
- end
- end
- -----<| CALL FUNCTIONS |>-----
- CloseUI(false)
- SetDraggable(true)
- SetInfo()
- OnButtonsClick()
- ShowButtons()
- end
- return Notification
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement