Problem with Udmi2

Im trying to get a position from a string. The position is {0, 171}, {0, 315} and its saved as a variable from the string <h1> don't forget the heading! <re>`{0, 176}, {0, 165}. My code is local func2 = string.sub(async[i], divider + 2, #async[i])

text.Position = UDim2.fromOffset(func2)

func2 translates to
“{0, 171}, {0, 315}” without the “”.

The problem is that when ever I convert the string to UDim2 it goes {0, 0}, {0, 0} no matter what .from or .new I set it to. If I just say the position is func2 then it will say nill. Im stuck in a pickle.

Can you please re-format your post? Im finding it a bit hard to follow. Why is there html in the post?

1 Like

I think you want:

UDim2.new(0, 171, 0, 315)

Idk why, but the brackets do more harm than good…

(Meant to reply to op, sorry…)

You can’t define an object’s property with a string if it’s a UDim2 value. You got to have each number using string methods again.

Assuming the code above retrieves the curly brackets,

local str, lastPosition = "{0, 12}, {0, 14}", 0 

local tableOfProperties = {
	[1] = "XScale",
	[2] = "XOffset",
	[3] = "YScale",
	[4] = "YOffset"
}

for i = 1, 4 do
	local f, l = string.find(str, "%d+", lastPosition + 1) 

	lastPosition = l
	
	tableOfProperties[i] = tonumber(string.sub(str, f, l))
end

local UDim2Value = UDim2.new(tableOfProperties[1], tableOfProperties[2], tableOfProperties[3], tableOfProperties[4]) 
print(UDim2Value)

text.Position = UDim2Value -- Now assign the UDim2 value

Reminder: It won’t work with decimals.

Remove the { and } and it should work fine

Im making a website creator and the code for it is part html