You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
Currently, I am trying to make a plugin that creates UIAspectRatioContraints for me as they are annoying to make. I am trying to divide the AbsoluteSize X and Y.
- What is the issue? Include screenshots / videos if possible!
The division is inaccurate and I do not understand why. Currently, dividing the absolute size together gets me an Aspect Ratio of β5.801β on a UI button, but manually dividing it in Windows Calculator gives me a Aspect Ratio of β5.743β
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I donβt even know what solutions I would use as this is so simple. Yes, I have searched on the Dev forum.
Here is my code.
local bar = plugin:CreateToolbar("Create UI Contraint")
local button = bar:CreateButton(
"Add Contraint",
"Adds a UIAspectRatio Contraint",
"http://www.roblox.com/asset/?id=14413281342"
)
local function main()
local Selection = game:GetService("Selection")
for _, object in pairs(Selection:Get()) do
if object:IsA("GuiObject") then
if object.Size.X.Offset == 0 or object.Size.Y.Offset == 0 then
local contraint = Instance.new("UIAspectRatioConstraint")
contraint.AspectRatio = object.AbsoluteSize.X / object.AbsoluteSize.Y
contraint.AspectType = Enum.AspectType.FitWithinMaxSize
contraint.DominantAxis = Enum.DominantAxis.Width
contraint.Parent = object
print("Created contraint!")
else
error("You are using offset for size instead of scale!")
end
else
error("Please select a GuiObject!")
end
end
end
button.Click:Connect(main)