Hey everyone!
I’m making a sandbox game with plots, and i would like to know how to save the position of each objects.
I already know how to save.
I will save the serialized ID for each object, and i will deserialized when loading saved data.
And then, i’ll save an array like this:
local savedArray = {}
for _, object in pairs(items) do
if objectsDictionnary:FindFirstChild(object.Name) then --Check if it is a real object.
local array = {
n = serialize(object.Name),
x = object.Position.X,
y = object.Position.Y, -- I'm not sure i'll need this value but i'll keep it for now.
z = object.Position.Z,
r = object.Orientation.Y
}
table.insert(savedArray, array)
end
end
The problem i’m facing is when the system will save the position of each objects, it will save the actual WorldPosition of the objects. So when the player rejoin, if he doesn’t have the same plot, all the saved position will be wrong.
So I’ll need to save the position based on the Grid of the Plot.$
Here is an image to show what I expect to do.
This is my grid, the size of the grid is 4 studs per tile.
I think I have to do something like this:
Something like this.
So when I save the position of an object I have to save the WorldPosition of the object - the position of the tile 0,0. So it should figure like this:
local savedArray = {}
for _, object in pairs(items) do
if objectsDictionnary:FindFirstChild(object.Name) then --Check if it is a real object.
local array = {
n = serialize(object.Name),
x = object.Position.X - ZeroTilePosition,
y = object.Position.Y - ZeroTilePosition, -- I'm not sure i'll need this value but i'll keep it for now.
z = object.Position.Z - ZeroTilePosition,
r = object.Orientation.Y
}
table.insert(savedArray, array)
end
end
I made this thread because I’m not sure on how to achive this.
Is it the good method? Did I made an error? Does it exist a better way to script this?
Thanks for your help!