Any way to make custom GUI resize more efficient?

I’m trying to make a desktop window simulation on roblox, and I’m making the custom resize. So, does anyone have any idea how to make this more efficient (in Code and speed)?

local Frame = script.Parent
local Window = script.Parent.Parent

local ValidInputs = {
	MovementTypes = {
		Enum.UserInputType.MouseMovement,
		Enum.UserInputType.Touch
	},
	ClickTypes = {
		Enum.UserInputType.MouseButton1,
		Enum.UserInputType.Touch
	}
}

local Resize = {
	ResizeX = false,
	ResizeY = false,
	InitialDragPosition = nil,
	InitialSize = UDim2.new(Window.Size.X.Scale, Window.Size.X.Offset, Frame.Size.X.Scale, Frame.Size.Y.Offset)
}

local function Update(Position)
	Resize.InitialDragPosition = Position
	Resize.InitialSize = UDim2.new(Window.Size.X.Scale, Window.Size.X.Offset, Frame.Size.X.Scale, Frame.Size.Y.Offset)
end

-- Frame Clicked --
Frame.InputBegan:Connect(function(Input)
	if table.find(ValidInputs.ClickTypes, Input.UserInputType) then
		if Input.Position.X > (Window.AbsolutePosition.X + Window.AbsoluteSize.X - 5) then
			Resize.ResizeX = true
		end
		if Input.Position.Y > (Frame.AbsolutePosition.Y + Frame.AbsoluteSize.Y - 5) then
			Resize.ResizeY = true
		end
		Update(Input.Position)
	end
end)

-- 

-- Frame Released --
Frame.InputEnded:Connect(function(Input)
	if table.find(ValidInputs.ClickTypes, Input.UserInputType) then
		Resize.ResizeX = false
		Resize.ResizeY = false
		Update(Input.Position)
	end
end)

game:GetService("UserInputService").InputChanged:Connect(function(Input)
	if table.find(ValidInputs.MovementTypes, Input.UserInputType) then
		local DragPosition = Input.Position - Resize.InitialDragPosition
		if Resize.ResizeX == true then
			local WindowSize = UDim2.new(Resize.InitialSize.X.Scale, Resize.InitialSize.X.Offset + DragPosition.X, Window.Size.Y.Scale, Window.Size.Y.Offset)
			game:GetService("TweenService"):Create(Window, TweenInfo.new(0.1), {Size = WindowSize}):Play()
		end
		if Resize.ResizeY == true then
			local FrameSize = UDim2.new(Frame.Size.X.Scale, Frame.Size.X.Offset, Resize.InitialSize.Y.Scale, Resize.InitialSize.Y.Offset + DragPosition.Y)
			game:GetService("TweenService"):Create(Frame, TweenInfo.new(0.1), {Size = FrameSize}):Play()
		end
	end
end)

There is a plugin for it.

If you need support for that, here is their discord server.

Hope this helps!

I’m speaking about window resizing. like this:
image
You drag the corners to change its size.

Ohhh, sorry, I misunderstood!

Hm…well, I am not so sure about that.

1 Like

Yep, its fine. I already solved it, Imma mark this as solved.

1 Like