From what I can see on the devforum, this is how you would check the data being used:
local success, errormessage = pcall(function()
data = Http:JSONDecode(MyDataStore:GetAsync(BuildsKey))
end)
print(string.len(Http:JSONEncode(data)))
The script prints 205,955 every time. Does this mean that it takes up 205,955 bytes? If not, how can I convert the length of the string into bytes so I can check the total amount of storage?
After looking it up online, thereâs about 4 MB total in the datastore, and currently 2,259 parts in my game (iâm saving the position, orientation, and name of the part, and also the playerâs UserId who placed the part)
A single datastore key can have a value of upto four megabytes in size assigned to it.
The script prints 205,955 every time. Does this mean that it takes up 205,955 bytes?
Yes, this is roughly accurate, all standard characters are represented by a single byte (numeric characters, alphabetic characters, punctuation characters etc.), the majority of characters that require 2-4 bytes to be stored are seldom used.
Would you mind sharing the current format/pattern of how data about a single part is stored?
Sorry for the late response, this is how I am currently saving the parts with their information. I make a table of information about the part including the name, position, orientation, and UserId of the person who placed the part. Then, I put that table into one big table which stores the properties of all parts I want to save, and I use JSONEncode/JSONDecode to save and load the information to the datastore
local PartsToSave = {}
for i,v in pairs(workspace:GetChildren()) do
if game.ReplicatedStorage.Builds:FindFirstChild(v.Name) then -- if the build can be saved then
local PartProperties = {
["Name"] = v.Name, -- name of the part
["Position"] = {v.Position.X,v.Position.Y,v.Position.Z}, -- position of the part
["Orientation"] = {v.Orientation.X,v.Orientation.Y,v.Orientation.Z}, -- orientation of the part
["Placer"] = v.Placer.Value -- person who placed the part
}
table.insert(PartsToSave, PartProperties) -- add the "PartProperties" table to another table called "PartsToSave"
end
end
local BuildsKey = "builds_save"
local success, errormesage = pcall(function()
if CanSave == true then
MyDataStore:SetAsync(BuildsKey, Http:JSONEncode(PartsToSave))
end
end)
Thatâs fine, you could compress positional and rotational data by locking placed parts to a 1x1 grid with 90 degree rotations. Iâd also recommend storing the playerâs ID instead of their name as the former is static whereas the latter is dynamic, on a final note you could store parts with an index, i.e; 1 through ânâ where ânâ is the number of parts, as opposed to storing each partâs name.
Right now, I am storing the playerâs UserId so players wonât lose a build if they change their username
Locking the part on a 1x1 grid or 90 degree rotations wouldnât be possible in my case because there is an option while building to disable snap to grid, and rotation increments are at 15 degrees
The reason I need to store the name is because Iâm trying to find the type of build in the folder called âBuildsâ (showed in the image below) then I can clone the build from the folder to the workspace, and apply the position/orientation