How do I Make a String into Udim2

I want to make it so that I can resize the GUI for each frame, using a stringvalue.

local tip = plrgui:WaitForChild('TipGui'):WaitForChild('TipLabel')
local frame = script.Parent
local tipsize = frame:WaitForChild('TipSize')

tip.Size = UDim2.new(tipsize.Value)

How do I make it so that I can change just the value of TipSize to change the size of TipLabel?

Is there something like tostring() but for Udim2?

1 Like

As you know, tostring is to convert a value to a string, but tonumber is to convert a string to a number.

local number = "1"

print(tonumber(number))
print(tonumber(tipsize.Value))
tip.Size = UDim2.new(tonumber(tipsize.Value))

I tried this but it printed nil

I believe this happens because the stringvalue has commas in between the numbers and you can’t change commas and numbers into a number.

You could use string.split and then unpack to do essentially:

local String =  game.Workspace.Value.Value ---0,0,100,0
String = string.split(String, ",")
local Udim = UDim2.new(table.unpack(String))

So in your case:

local tip = plrgui:WaitForChild('TipGui'):WaitForChild('TipLabel')
local frame = script.Parent
local tipsize = frame:WaitForChild('TipSize')

local NewString =  string.split(tipsize.Value, ",")
tip.Size = UDim2.new(table.unpack(NewString))

And yes it returns nil because it has commas, as something like β€œ0,1,0,1” cannot be converted into a number through the tonumber method/function

5 Likes