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:
--require(workspace.guimaker.guimakermod).buildgui()
local mod = {}
local guiparts = script.Parent.guiparts
local guiobjects = script.Parent.guiobjects
local function v2(pos)
return Vector2.new(pos.x, pos.y)
end
local function get2doffset(pos1, pos2)
return Vector2.new(pos1.x - pos2.x, pos1.y - pos2.y)
end
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 UDim2.new(newpos.x, 0, newpos.y, 0),
UDim2.new(newsize.x, 0, newsize.y, 0)
end
local function newguiobject(part)
local obj = guiobjects:FindFirstChild(part.Name)
if obj then
obj = obj:Clone()
obj.BackgroundColor3 = part.Color
return obj
end
return
end
mod.buildgui = function(name)
local gui = Instance.new("ScreenGui") do
gui.Name = name or "Gui"
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
gui.Parent = game.StarterGui
end
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
wait()
createframes(v)
end
end
createframes(guiparts)
end
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.