Get Vector3 From String Value

How would I get a vector3 value from a string value in a script?

Why use a string value to store a vector when there’s a value called Vector3Value

local VectorValue = script.Parent.Vector3Value
VectorValue.Value = Vector3.new(0,0,0)
print(VectorValue.Value)
1 Like

I would suggest doing something like this:

--Storing the string
local Str = 'X=100,Y=100,Z=100'
--Using the Sting
local Pos = Vector3.new(tonumber(string.split(string.split(Str, 'X=')[2], ',')), tonumber(string.split(string.split(Str, 'Y=')[2], ',')), tonumber(string.split(string.split(Str, 'Z=')[2], ',')),)

Then Pos will equal the vector of the string

For it to work the string has to be stored like that with the ='s and the x,y,z and ,

i would say store the vector as a table if you can though, it would be much easier

to save time and make it more readable you could also just do

local vec_str = "100:100:100"

local vec_com = string.split(vec_str, ":")

local vector = Vector3.new(vec_com[1], vec_com[2], vec_com[3])
3 Likes

oh dang your right, Lol overthinkin things

local VectorString = "-0 -0 -0"
local Vector = Vector3.new(table.unpack(VectorString:split(" ")))
print(Vector) -- -0, -0, -0
2 Likes