Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- spawnButton(frame,connected function, 1/2)
- -- 1/2 means Mouse1/2
- -- Only works for player gui due to complications with the "Destroying" bindable.
- local function spawnButton(p1, p2, p3)
- local released = false;
- local Player = game:GetService("Players").LocalPlayer;
- local Mouse = Player:GetMouse();
- local min_x = p1.AbsolutePosition.X;
- local min_y = p1.AbsolutePosition.Y;
- local max_y = min_y + p1.Size.Height.Offset;
- local max_x = min_x + p1.Size.Width.Offset;
- local p5 = p1.Changed:Connect(function(change)
- local p4 = tostring(change);
- if p4 == "AbsolutePosition" or p4 == "Position" then
- min_x = p1.AbsolutePosition.X;
- min_y = p1.AbsolutePosition.Y;
- max_y = min_y + p1.Size.Height.Offset;
- max_x = min_x + p1.Size.Width.Offset;
- end;
- end);
- local p6 = Mouse.Button2Up:Connect(function()
- 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
- released = true;
- end;
- end);
- local p7 = Mouse.Button1Up:Connect(function()
- if p3 == 1 or p3 == nil or not p3 then
- 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
- released = true;
- end;
- end;
- end);
- local p8 = game:GetService("RunService").RenderStepped:Connect(function()
- if released then
- p2();
- released = false;
- end;
- end);
- task.spawn(function()
- while task.wait() do
- local p9 = Player:FindFirstChild("PlayerGui"):GetDescendants();
- local p10 = false;
- for _,v in pairs(p9) do
- if v == p1 then
- p10 = true;
- end;
- end;
- if p10 == false then
- p5:Disconnect();
- p6:Disconnect();
- p7:Disconnect();
- p8:Disconnect();
- break;
- end;
- end;
- end)
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement