Advertisement
FXDuke

Roblox Button Maker

Sep 6th, 2022 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. -- spawnButton(frame,connected function, 1/2)
  2. -- 1/2 means Mouse1/2
  3. -- Only works for player gui due to complications with the "Destroying" bindable.
  4.  
  5. local function spawnButton(p1, p2, p3)
  6.     local released = false;
  7.     local Player = game:GetService("Players").LocalPlayer;
  8.     local Mouse = Player:GetMouse();
  9.     local min_x = p1.AbsolutePosition.X;
  10.     local min_y = p1.AbsolutePosition.Y;
  11.     local max_y = min_y + p1.Size.Height.Offset;
  12.     local max_x = min_x + p1.Size.Width.Offset;
  13.     local p5 = p1.Changed:Connect(function(change)
  14.         local p4 = tostring(change);
  15.         if p4 == "AbsolutePosition" or p4 == "Position" then
  16.             min_x = p1.AbsolutePosition.X;
  17.             min_y = p1.AbsolutePosition.Y;
  18.             max_y = min_y + p1.Size.Height.Offset;
  19.             max_x = min_x + p1.Size.Width.Offset;
  20.         end;
  21.     end);
  22.     local p6 = Mouse.Button2Up:Connect(function()
  23.         if Mouse.X > min_x and Mouse.X < max_x and Mouse.Y > min_y and Mouse.Y < max_y and p3 == 2 and p1.Visible == true then
  24.             released = true;
  25.         end;
  26.     end);
  27.     local p7 = Mouse.Button1Up:Connect(function()
  28.         if p3 == 1 or p3 == nil or not p3 then
  29.             if Mouse.X > min_x and Mouse.X < max_x and Mouse.Y > min_y and Mouse.Y < max_y and p1.Visible == true then
  30.                 released = true;
  31.             end;
  32.         end;
  33.     end);
  34.     local p8 = game:GetService("RunService").RenderStepped:Connect(function()
  35.         if released then
  36.             p2();
  37.             released = false;
  38.         end;
  39.     end);
  40.     task.spawn(function()
  41.         while task.wait() do
  42.             local p9 = Player:FindFirstChild("PlayerGui"):GetDescendants();
  43.             local p10 = false;
  44.             for _,v in pairs(p9) do
  45.                 if v == p1 then
  46.                     p10 = true;
  47.                 end;
  48.             end;
  49.             if p10 == false then
  50.                 p5:Disconnect();
  51.                 p6:Disconnect();
  52.                 p7:Disconnect();
  53.                 p8:Disconnect();
  54.                 break;
  55.             end;
  56.         end;
  57.     end)
  58. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement