Hello. I am trying to make a simple plugin that takes the selection of GuiObjects, and changes their Size and Position values to be based entirely off of Scale rather than offset. However, when I try to run it, it gives me the error “Offset cannot be assigned to - Edit - Script:10”. I have tried looking elsewhere, and I am unsure as to why the error is occurring, as I’m just changing the offset of each UDim in the UDim2 to be 0. Is there a specific method that I should be using instead?
local screenSize = workspace.Camera.ViewportSize
local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Offset to Scale Conversion")
local button = toolbar:CreateButton("Convert", "Converts a GUI offset to scale", "rbxassetid://14978048121")
--same image as the one from the tutorial as i dont really care about the way it looks
local function makeUdims(x, y, old)
local udim = UDim2.new((x/screenSize), 0, (y/screenSize), 0)
udim = udim+old
udim.X = UDim.new(udim.X.Scale, 0)
udim.Y = UDim.new(udim.Y.Scale, 0)
return udim
end
local function convertOffsetToScale()
local selectedObjects = Selection:Get()
if #selectedObjects>0 then
for i,v in pairs(selectedObjects) do
if v:IsA("GuiObject") then
print("ete")
local pos = v.Position
local size = v.Size
pos = makeUdims(pos.X.Offset, pos.Y.Offset, pos)
size = makeUdims(size.X.Offset, size.Y.Offset, size)
v.Position = pos
v.Size = size
end
end
end
end
button.Click:Connect(convertOffsetToScale)