Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can't insert a Vector3 inside a table?

Well I'm always in the tables :3.

Here is my script:

local HttpService = game:GetService("HttpService")

local ModelName = "JustAModel"
local Position = Vector3.new (10, 11, 12)
local Rotation = Vector3.new (0, 90, 0)
local MOD = {}
MOD[ModelName] =  {Pos = Position, Rot = Rotation, LOL = Vector3.new(1, 1, 1)}
local json = HttpService:JSONEncode(MOD)
print(json)

It's printing this: (It's encoded in json)

{"JustAModel":{"Pos":null,"Rot":null,"LOL":null}} Well anyone have a clue for that >_>?

Thanks for EchoReaper :P

2 answers

✓ Accepted answer

JSON does not support ROBLOX datatypes. If you want to store ROBLOX instances in that format, you'll need to manually convert them to strings before saving, and convert them from strings back to instances when you decode the table later on.

1 comment

0

Well thanks I readed this too https://forum.roblox.com/Forum/ShowPost.aspx?PostID=45625862, I need to use loastring() and savestring()...

The problem is that JSONEncode cannot convert Vector3s. I would recommend storing each component individually, possibly in a table:

MOD[ModelName] = {Pos = {X = Position.X, Y = Position.Y, Z = Position.Z}, Rot = {X = Rotation.X, Y = Rotation.Y, Z = Rotation.Z}, LOL = {X = 1, Y = 1, Z = 1}}

You could probably write a function to convert a Vector3 to such a table.

3 comments

0

Well thanks, it's a good idea too, but it's harder, so I'll try to write loadstring("return Vector3.new(1, 1, 1)")() so it can load the Vector3 and to save I'll just do "return"..tostring("Vector3.new("Position')') It should work maybe

1

You probably don't need to use the loadstring function at all.

0

Well I got wrong, it's the CFrame.new, not the Vector3.new >_>

This discussion is preserved as it was. New answers, comments, and votes are closed.