So I am making a resizable gui, the problem is though that any extra gui elements including the button itself seems to detach from the gui.
This is the main script:
local b = script.Parent.ResizableButton
local mouse = game.Players.LocalPlayer:GetMouse()
local Pressing = false
local RecordedLastX = nil
local RecordedLastY = nil
local NowPositionX = nil
local NowPositionY = nil
local Hovered = false
local Frame = script.Parent
b.InputBegan:connect(function(key)
if key.UserInputType == Enum.UserInputType.MouseButton1 then
Pressing = true
RecordedLastX = mouse.X
RecordedLastY = mouse.Y
b.InputEnded:connect(function(key2)
if key == key2 then
Pressing = false
end
end)
end
end)
b.MouseEnter:connect(function()
Hovered = true
b.MouseLeave:connect(function()
Hovered = false
RecordedLastX = mouse.X
RecordedLastY = mouse.Y
end)
end)
mouse.Move:connect(function()
if Pressing == true and Hovered == true then
NowPositionX = mouse.x
NowPositionY = mouse.y
local ChangeX = NowPositionX - RecordedLastX
local ChangeY = NowPositionY - RecordedLastY
RecordedLastX = mouse.X
RecordedLastY = mouse.Y
Frame.Size = UDim2.new(0, Frame.Size.X.Offset + ChangeX, 0, Frame.Size.Y.Offset + ChangeY)
b.Position = UDim2.new(0, b.Position.X.Offset + ChangeX, 0, b.Position.Y.Offset + ChangeY)
end
end)
And this is the resize script:
local Min = 200
local Max = 1000
local Object = script.Parent
Object.Changed:connect(function()
if Object.Size.X.Offset < Min and Object.Size.Y.Offset < Min then
Object.Size = UDim2.new(0, Min, 0, Min)
elseif Object.Size.X.Offset < Min then
Object.Size = UDim2.new(0, Min, 0, Object.Size.Y.Offset)
elseif Object.Size.Y.Offset < Min then
Object.Size = UDim2.new(0, Object.Size.X.Offset, 0, Min)
end
if Object.Size.X.Offset > Max and Object.Size.Y.Offset > Max then
Object.Size = UDim2.new(0, Max, 0, Max)
elseif Object.Size.X.Offset > Max then
Object.Size = UDim2.new(0, Max, 0, Object.Size.Y.Offset)
elseif Object.Size.Y.Offset > Max then
Object.Size = UDim2.new(0, Object.Size.X.Offset, 0, Max)
end
end)
Is there a way I can modify this to make it so the guis stay together and stay in proportion?