Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local mouse = player:GetMouse()
- local gui = script.Parent
- local frameMain = gui:WaitForChild("Frame")
- local amount = 12 -- total = amount^2
- for y = 1, amount do
- for x = 1, amount do
- local newFrame = Instance.new("Frame")
- newFrame.ZIndex = 2
- newFrame.Size = UDim2.new(0, frameMain.AbsoluteSize.X / amount, 0, frameMain.AbsoluteSize.Y / amount)
- newFrame.Position = UDim2.new(0, (x - 1) * frameMain.AbsoluteSize.X / amount, 0, (y - 1) * frameMain.AbsoluteSize.Y / amount)
- newFrame.Parent = frameMain
- end
- end
- local dragging = false
- local thing = Instance.new("Frame")
- thing.ZIndex = 3
- thing.Size = UDim2.new(0, frameMain.AbsoluteSize.X / amount, 0, frameMain.AbsoluteSize.Y / amount)
- thing.Position = UDim2.new(0.5, -thing.Size.X.Offset / 2, 0, 0)
- thing.BackgroundColor3 = Color3.new(0, 1, 0)
- thing.InputBegan:Connect(function(input)
- if input.UserInputType ~= Enum.UserInputType.MouseButton1 then
- return
- end
- dragging = true
- end)
- thing.InputEnded:Connect(function(input)
- if input.UserInputType ~= Enum.UserInputType.MouseButton1 then
- return
- end
- dragging = false
- local frames = frameMain:GetChildren()
- do
- local mousePos = Vector2.new(input.Position.X, input.Position.Y)
- table.sort(frames, function(f1, f2)
- local f1Pos = f1.AbsolutePosition + f1.AbsoluteSize / 2
- local f2Pos = f2.AbsolutePosition + f2.AbsoluteSize / 2
- return (mousePos - f1Pos).Magnitude < (mousePos - f2Pos).Magnitude
- end)
- end
- thing.Position = UDim2.new(0, frames[1].AbsolutePosition.X, 0, frames[1].AbsolutePosition.Y)
- end)
- game:GetService("RunService").RenderStepped:Connect(function()
- if dragging then
- thing.Position = UDim2.new(0, mouse.X - thing.Size.X.Offset / 2, 0, mouse.Y - thing.Size.Y.Offset / 2)
- end
- end)
- thing.Parent = gui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement