UDim2 conversion issue

image
I’m trying to make the buttons from the left once cloned on the computer widget to have the same size in pixels.

Although the buttons on the left are in scale, and on the computer frame they’re in offset

Here’s my script for the conversion

newUI.title.MouseButton1Click:Connect(function()
			local newC = newUI:Clone()
			newC.Size = UDim2.fromOffset(newC.Size.X.Scale*cX,newC.Size.Y.Scale*cY)
			task.wait()
			newC.Parent = sWidget
			newC.Position = UDim2.fromScale(0,0)
			MakeGrabbable(newC.title,newC)
		end)

NewUI reffers to the buttons on the left.

If neccersary, this is the entire script for rendering both the side buttons and conversion

local function LoadGateUI()
	local loadindex = 0
	local cin = 100
	local sv = 0
	for nodename, nodedata in pairs(Nodes) do
		loadindex+=1
		local newUI = nodeBase:Clone()
		newUI.Parent = scroll
		local sizefactor = 1/25
		newUI.Position = UDim2.fromScale(0,(loadindex-1)/25+sv)

		if #nodedata.inputs > 3 or #nodedata.outputs > 3 then
			local top = #nodedata.inputs if #nodedata.outputs > #nodedata.inputs then top = #nodedata.outputs end
			sizefactor = (1/25)*(top/4)
			sv+= sizefactor-(1/25)
		end
		newUI.Size = UDim2.fromScale(0.934,sizefactor)
		newUI.title.Text = nodename
		newUI.BackgroundColor3 = nodedata.bcol
		for order, input in pairs(nodedata.inputs) do
			local NodeCopy = inpcopy:Clone()
			NodeCopy.Size = UDim2.fromScale(0.03,1/#nodedata.inputs)
			NodeCopy.Position = UDim2.fromScale(0,(order-1)/#nodedata.inputs)
			NodeCopy.Name = input
			NodeCopy.Parent = newUI
		end
		for order, output in pairs(nodedata.outputs) do
			local NodeCopy = inpcopy:Clone()
			NodeCopy.Size = UDim2.fromScale(0.3,1/#nodedata.outputs)
			NodeCopy.Position = UDim2.fromScale(0.97,(order-1)/#nodedata.outputs)
			NodeCopy.Name = output
			NodeCopy.Parent = newUI
		end
		newUI.title.MouseButton1Click:Connect(function()
			local newC = newUI:Clone()
			newC.Size = UDim2.fromOffset(newC.Size.X.Scale*cX,newC.Size.Y.Scale*cY)
			task.wait()
			newC.Parent = sWidget
			newC.Position = UDim2.fromScale(0,0)
			MakeGrabbable(newC.title,newC)
		end)
	end
end

still having problems with ths, if anyone knows a solution please reply!

use gridlayout or listlayout in the frame it will do it auto

it called UIGridLayout take look about it in roblox or youtupe

I have no problem with the scroll UI, the problem is at making the new UI in the computer widget to be a pixel replica of the same frames on the scroll

Why not use newC.AbsoluteSize?

1 Like

I’m not very experienced in Roblox scripting, so if you could explain your solution, that’d be great. Thanks!

This should help you, what it does is it will convert your Scale and Offset to pixels by giving it a parent that has a size of 1, 1
– this is the parent UDim2
local parent = UDim2.new(0, 0, 0, 0)

– this is what will get converted
local scaleOffset = UDim2.new(0, 0, 0, 0)

– this will convert it to pixels
local pixels = UDim2.new(0, scaleOffset.X.Offset + (parent.X.OffsetscaleOffset.X.Scale), 0, scaleOffset.Y.Offset + (parent.Y.OffsetscaleOffset.Y.Scale))

To update i fixed the issue with some absolute size and absolute position calculations and it all works fine.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.