So basically I want to store the initial positions of GUIS. This is being done in a for child in pairs loop. However, since there is no Udim2 value to place in the child, I put in a stringvalue instead, and filtered out the brackets. However, to convert it back to a UDim2, I also need to have the number values in the strings (0,5,6,1) for example, to be numbers, and if i use tonumber() it returns nil as the commas cannot be numbers. Hopefully that makes sense and explains my problem well enough?
Just in case that made no sense whatsoever:
local player = game.Players.LocalPlayer for i, child in pairs(player.PlayerGui.ScreenGui.Frame:GetChildren()) do local a = Instance.new("TextLabel",child) a.Text = tostring(child.Position) end wait(10) script.Parent:TweenPosition(UDim2.new(0.366, 0,0.135, 0),"In",.5) game.ReplicatedStorage.Sound:Play() wait(1) script.Parent.Sound:Play() for i, child in pairs(player.PlayerGui.ScreenGui.Frame:GetChildren()) do local c = (string.gsub(child.TextLabel.Text,"{","")) local b = tonumber(string.gsub(c,"}","")) print(b) child:TweenPosition(UDim2.new(b),"Out",.35) end
I would use a JSON string to hold this data which whould be simple due to the fact that a UDim2 prints as an array. ie {0, 0}, {0, 0}
meaning that you convert it to an JSON array [[0,0],[0,0]]
Example:-
local defUDim2 = UDim2.new(0, 320, 0.5, 12) print('UDim2 value is ', defUDim2) -- formats string as a JSON local function encode(data) return '['.. data:gsub('{', '['):gsub('}', ']') .. ']' end -- returns a table from the JSON local function decode(data) return game:GetService('HttpService'):JSONDecode(data) end local encData = encode(tostring(defUDim2)) print('encoded UDim2 as JSON ', encData) -- now a table local decData = decode(encData) local tmpUDim2 = UDim2.new(decData[1][1], decData[1][2], decData[2][1], decData[2][2]) print('Output UDim2 is ', tmpUDim2)
There are other ways this can be done this is just an example.
I hope this helps.