Howdy devs.
Do any of you know how I’d be able to save all placed parts in a workspace and also load them when the player joins? I’m using this for a building system, much like the famous game “Plane Crazy”. If anyone can guide me in the right direction, that would be stellar.
You could either save them as strings, bools, or numbers inside a Dictionary of some sort when you save the Data for the player
Possibly something like this?
local PartsToSave = {
Part1Position = {
X = 50,
Y = 0,
Z = 30,
}
Part2Position = {
X = 40,
Y = 5,
Z = 32,
}
}
Usually, you would get the center of the “base”, and use baseCenterCFrame:ToObjectSpace(blockCFrame) to find the relative position.
You can make it relative to the world with baseCenterCFrame:ToWorldSpace(savedCFrame).
If you want the data to take as little space as possible, you would save the LookVector and the x, y, z components.
If you don’t really care about storage, you could just save the entire CFrame.
Since you can’t store a userdata in a datastore, you have to use tables to store the components.
When I want to load these parts into the game, would I use a for loop to do so? How would you recommend doing it?
Since your base data is in a table, you have to iterate through the table to deserialize and load them.
You could have a Save function and a Load function.
local function Save(base)
local serialized = {}
for i, v in pairs(base:GetChildren()) do
-- stuff
end
return serialized
end
-- and a load function
local function Load(serialized)
local base = Instance.new("Model")
for i, v in pairs(serialized) do
-- do stuff
end
return base
end
That narrows things down a lot, thanks. I’ll give it a shot and get back to you in the near future.