You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I want to convert strings into Vector3
- What is the issue?
There so much i could do, theres Vector3.new, BasePart.Position, Vector3 other methods, CFrame.Position. I do not know what to do
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I asked coding bacon and its only for the vector3 methods not BasePart.Position, and CFrame.Position and theres only 1 more topic talking about this which is not much help
This is the code which is given to me
function module:StringToVector3(str)
str = str:gsub("%s+", "")
if str == "Vector3.zero" then
return Vector3.zero
end
if str == "Vector3.one" then
return Vector3.one
end
local axis = str:match("Vector3%.fromAxis%(Enum%.Axis%.(%a+)%)")
if axis then
local enumAxis = Enum.Axis[axis]
if enumAxis then
return Vector3.fromAxis(enumAxis)
end
end
local normalId = str:match("Vector3%.fromNormalId%(Enum%.NormalId%.(%a+)%)")
if normalId then
local enumNormalId = Enum.NormalId[normalId]
if enumNormalId then
return Vector3.fromNormalId(enumNormalId)
end
end
local vx, vy = str:match("Vector3%.FromVector2%(([-%d%.]+),([-%d%.]+)%)")
if vx and vy then
return Vector3.FromVector2(Vector2.new(tonumber(vx), tonumber(vy)))
end
local x, y, z = str:match("Vector3%.new%(([-%d%.]+),([-%d%.]+),([-%d%.]+)%)")
if x and y and z then
return Vector3.new(tonumber(x), tonumber(y), tonumber(z))
end
x, y, z = str:match("Vector3%(([-%d%.]+),([-%d%.]+),([-%d%.]+)%)")
if x and y and z then
return Vector3.new(tonumber(x), tonumber(y), tonumber(z))
end
x, y, z = str:match("{([-%d%.]+),([-%d%.]+),([-%d%.]+)}")
if x and y and z then
return Vector3.new(tonumber(x), tonumber(y), tonumber(z))
end
x, y, z = str:match("^([-%d%.]+),([-%d%.]+),([-%d%.]+)$")
if x and y and z then
return Vector3.new(tonumber(x), tonumber(y), tonumber(z))
end
warn("Invalid Vector3 string: " .. str)
return nil
end
It does support {1, 1, 1}, (1, 1, 1) and whatever