Issues with Part to Gui converter module

Hello devforum, I was making a small module to make creating guis easier.

I absolutely don’t like gui designing so I decided to write myself a little script that can convert parts to an gui to make gui designing much faster and easier.

Here is the code.

--The command:

local mod = {}

local guiparts = script.Parent.guiparts
local guiobjects = script.Parent.guiobjects

local function v2(pos)
	return, pos.y)

local function get2doffset(pos1, pos2)
	return - pos2.x, pos1.y - pos2.y)

local function toudim2(p)
	local corn1 = v2(p.Parent.Position - (p.Parent.Size / 2))
	local corn2 = v2(p.Parent.Position + (p.Parent.Size / 2))
	local psize = get2doffset(corn1, corn2)
	local pos = v2(p.Position - (p.Size / 2))
	local size = v2(p.Size)
	local newpos = get2doffset(corn1, pos) / psize
	local newsize = get2doffset(pos, pos + size) / psize
	return, 0, newpos.y, 0),, 0, newsize.y, 0)

local function newguiobject(part)
	local obj = guiobjects:FindFirstChild(part.Name)
	if obj then
		obj = obj:Clone()
		obj.BackgroundColor3 = part.Color
		return obj

mod.buildgui = function(name)
	local gui ="ScreenGui") do
		gui.Name = name or "Gui"
		gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
		gui.Parent = game.StarterGui
	local function createframes(obj)
		for k, v in ipairs(obj:GetChildren()) do
			local frame = newguiobject(v)
			local pos, size = toudim2(v)
			frame.Position = pos
			frame.Size = size
			frame.Parent = gui
			gui = frame

return mod

These are the parts.

And this is basically what it does.

First issue, frame is parented incorrectly.

How it’s supposed to be:

What it does now:

The secondary issue is that the world position/size to Gui position/size conversion has some small issues.
The position is incorrect or seems upside-down (might be an easy fix, but I’m out of brain power)?

The size seems to work fine, but there is issues with the position.

If anyone can help me out with this that’d be amazing.

This gui isn’t much but it was just a test.
I absolutely don’t like making guis so I wanted to make a module where I just place parts in the workspace and it converts that to a gui with all colors, zindexes, sizes and positions correct.

Thanks for taking time to read this, help is very much appreciated here since I’m actually a bit stuck and a little tired.

1 Like

I somehow managed to fix it without really knowing how, it happened by coincidence when I started trying things I did not expect to work.
It no longer inverts the Y axis and the guis are now parented correctly.

Doubt if this will become a plugin or anything but it’s pretty darn useful since it just converts parts to gui elements correctly and pretty accurately.

Thanks for taking the time to read though.

1 Like

Yeah this is actually really cool.

1 Like