Converting CFrame to a text value for textlabels?

I want to make a script where the coordinates your character’s HumanoidRootPart CFrame is recorded via pressing the save button on the GUI. I’ve checked everywhere and couldn’t find the right one for my current situation. Does anyone know?

You can use tostring() for that!

local partCframe = workspace.Part.CFrame -- Location here
local String = tostring(partCframe)
5 Likes
function StringToCFrame(str)
	local Split = string.split(str, ",")
	return CFrame.new(Split[1],Split[2],Split[3],Split[4],Split[5],Split[6],Split[7],Split[8],Split[9],Split[10],Split[11],Split[12])
end

and the reverse

If you just want the coordinates, you can concatenate the position values with commas:

--Part is the player's HumanoidRootPart
local position_string = Part.CFrame.X..', '..Part.CFrame.Y..', '..Part.CFrame.Z

And then you can convert it back to CFrame with JSON Decode, something like:

local http = game:GetService('HttpService')
local position_table = http:JSONDecode('['..position_string..']') --puts brackets around the string which turns it into JSON
local position = CFrame.new(unpack(position_table))
1 Like

That was what I wanted, thank you! I also changed it from being a CFrame to a Vector3! That would’ve been such an easy fix if I just looked more!