How would I convert a vector3 to a number string?
1 Like
like Vector3.new(1,2,3) → 123 ?
in that case :
text = vec.X..vec.Y..vec.Z
Explanation
vec.X --> gets X
.. --> combine 2 text/numbers
vec.X .. vec.Y --> XY
vec.X..vec.Y..vec.Z --> XYZ
local VectorThing = Vector3.new(1,2,4)
local function VectorToString(V3: Vector3): string
return ("%.1f, %.1f, %.1f"):format(V3.X, V3.Y, V3.Z) -- "%.1f is to the nearest tenth, %.2f is to nearest hundredth etc etc"
end
local function VectorStringToVector(VectorString : string): Vector3
local split = VectorString:split(",")
return Vector3.new(split[1], split[2], split[3])
end
local VectorString = VectorToString(VectorThing) -- "1, 2, 4"
local BackToVector = VectorStringToVector(VectorString) -- Vector3(1, 2, 4)
6 Likes
This worked perfectly, thank you!
local function VectorToString(v3)
return v3.X.." "..v3.Y.." "..v3.Z
end
local function StringToVector(s)
return Vector3.new(table.unpack(s:split(" ")))
end
2 Likes