Advertisement
Guest User

roblox notification system

a guest
May 20th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. function Create(ty)
  2. return function(data)
  3. local obj = Instance.new(ty)
  4. for k, v in pairs(data) do
  5. if type(k) == 'number' then
  6. v.Parent = obj
  7. else
  8. obj[k] = v
  9. end
  10. end
  11. return obj
  12. end
  13. end
  14.  
  15. function GetCurrentNotifyGuis(player)
  16. local guis = {}
  17. for i,v in pairs(player.PlayerGui:GetChildren()) do
  18. if v.Name == "Notification" then
  19. if v:findFirstChild("NotifyFrame") and v.NotifyFrame:IsA("Frame") then
  20. local guiInfo = {}
  21. table.insert(guiInfo,v)
  22. if v.NotifyFrame.Position.Y.Offset == -120 then
  23. table.insert(guiInfo,1)
  24. elseif v.NotifyFrame.Position.Y.Offset == -190 then
  25. table.insert(guiInfo,2)
  26. end
  27. table.insert(guis,guiInfo)
  28. end
  29. end
  30. end
  31. return guis
  32. end
  33.  
  34. function getGui(title,message,image,timeout,callback)
  35. local gui = Create'ScreenGui'{
  36. Name = "Notification";
  37. Create'Frame'{
  38. Size = UDim2.new(0, 200, 0, 67);
  39. Style = Enum.FrameStyle.RobloxRound;
  40. Name = "NotifyFrame";
  41. Position = UDim2.new(1, 0, 1, -120);
  42. Create'ImageLabel'{
  43. Image = image;
  44. ZIndex = 2;
  45. Size = UDim2.new(0.26, 0, 0.95, 0);
  46. Name = "image";
  47. BackgroundTransparency = 1;
  48. };
  49. Create'TextLabel'{
  50. Text = title;
  51. Size = UDim2.new(0.69, 0, 0.3, 0);
  52. TextColor3 = Color3.new(1, 1, 1);
  53. TextWrap = true;
  54. Font = Enum.Font.ArialBold;
  55. Name = "Title";
  56. Position = UDim2.new(0.26, 0, 0, 0);
  57. BackgroundTransparency = 1;
  58. TextScaled = true;
  59. };
  60. Create'TextLabel'{
  61. Text = message;
  62. Size = UDim2.new(0.69, 0, 0.2, 0);
  63. TextColor3 = Color3.new(1, 1, 1);
  64. TextWrap = true;
  65. Name = "Message";
  66. Position = UDim2.new(0.26, 0, 0.6, 0);
  67. BackgroundTransparency = 1;
  68. TextScaled = true;
  69. };
  70. Create'ImageButton'{
  71. Image = "rbxasset://textures/ui/CloseButton.png";
  72. ZIndex = 4;
  73. Size = UDim2.new(0, 20, 0, 20);
  74. BackgroundTransparency = 1;
  75. Name = "Close";
  76. Position = UDim2.new(0.925, 0, -0.1, 0);
  77. };
  78. Create'TextButton'{
  79. ZIndex = 3;
  80. Name = "CloseOverlay";
  81. Text = "";
  82. Size = UDim2.new(1, 0, 1, 0);
  83. BackgroundTransparency = 1;
  84. };
  85. };
  86. };
  87. gui.NotifyFrame.CloseOverlay.MouseButton1Up:connect(function ()
  88. if callback then
  89. callback()
  90. end
  91. gui.NotifyFrame:TweenPosition(UDim2.new(1,0,1,gui.NotifyFrame.Position.Y.Offset),"Out","Linear",1,true,nil)
  92. wait(1)
  93. gui:Destroy()
  94. end)
  95. gui.NotifyFrame.Close.MouseButton1Up:connect(function ()
  96. if callback then
  97. callback()
  98. end
  99. gui.NotifyFrame.Close.Image = "rbxasset://textures/ui/CloseButton.png"
  100. gui.NotifyFrame:TweenPosition(UDim2.new(1,0,1,gui.NotifyFrame.Position.Y.Offset),"Out","Linear",1,true,nil)
  101. wait(1)
  102. gui:Destroy()
  103. end)
  104. gui.NotifyFrame.Close.MouseButton1Down:connect(function ()
  105. gui.NotifyFrame.Close.Image = "rbxasset://textures/ui/CloseButton_dn.png"
  106. end)
  107. gui.NotifyFrame.Close.MouseLeave:connect(function ()
  108. gui.NotifyFrame.Close.Image = "rbxasset://textures/ui/CloseButton.png"
  109. end)
  110. delay(timeout,function ()
  111. if gui:findFirstChild("NotifyFrame") then
  112. gui.NotifyFrame:TweenPosition(UDim2.new(1,0,1,gui.NotifyFrame.Position.Y.Offset),"Out","Linear",1,true,nil)
  113. wait(1)
  114. gui:Destroy()
  115. end
  116. end)
  117. return gui
  118. end
  119.  
  120. _G.SendNotification = function (player,title,message,image,timeout,callback)
  121. if game.Players:findFirstChild(player.Name) == nil then return error("Argument 1 missing or nil") end
  122. if #GetCurrentNotifyGuis(player) > 2 then return end
  123. if type(title) ~= "string" then return error("Attempt to use '"..title.."' for string 'title'") end
  124. if type(message) ~= "string" then return error("Attempt to use '"..message.."' for string 'message'") end
  125. if type(image) ~= "string" then return error("Attempt to use '"..image.."' for content 'image'") end
  126. if type(timeout) ~= "number" then timeout = 999999 end
  127. local guis = GetCurrentNotifyGuis(player)
  128. if #guis ~= 0 then
  129. for i = 1,#guis do
  130. if guis[i][2] == 1 then
  131. guis[i][1].NotifyFrame:TweenPosition(UDim2.new(1,-200,1,-190),"Out","Linear",1,true,nil)
  132. else
  133. guis[i][1].NotifyFrame:TweenPosition(UDim2.new(1,0,1,-190),"Out","Linear",1,true,nil)
  134. game:GetService("Debris"):AddItem(guis[i][1],1)
  135. end
  136. end
  137. end
  138. local gui = getGui(title,message,image,timeout,callback)
  139. gui.Parent = player.PlayerGui
  140. gui.NotifyFrame:TweenPosition(UDim2.new(1,-200,1,-120),"Out","Quad",1,true,nil)
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement