So I need to convert Udim2 to Vector2 and I stumbled across this function on the roblox forums. The only problem is I keep on getting this error : attempt to index field 'X' (a number value). So I decided to break the math up into separate lines to see which line is causing the error. It says it is happening on line 6. Here is the function, any help is greatly appreciated!
local function toV2(ud2) local scr = c.ViewportSize local x = math.floor((ud2.X.Scale* scr.X) +0.5) + ud2.X.Offset local y = math.floor((ud2.Y.Scale* scr.Y) +0.5) + ud2.Y.Offset return Vector2.new(x,y) end
I just decided that it is better to format my vector2 accordingly to the parent frame. For anyone interested here was the function I wrote:
function formatV2(v2) local c = game.Workspace.CurrentCamera local scr = c.ViewportSize local xOff = script.Parent.Parent.Position.X.Scale * scr.X local x = v2.X - xOff local yOff = script.Parent.Parent.Position.Y.Scale * scr.Y local y = v2.Y - yOff return Vector2.new(x,y) end