Any feedback on my datastore?

So i got this to save the propeties of a model. Is there anything i could improve or is it good enough?. Please be honest all feedback is higly appreciated :smiley:

Also the table is converted into a json string when saving begins

	for _, v in pairs(FOLDER:GetChildren()) do -- // FOLDER IS WHERE ALL THE MODELS ARE LOCATED
					if v:IsA("Model") then
						--local ON = 0
						table.insert(DATA_TABLE, {
							["OBJECT"] = v.Name,
							["X"] = v.PrimaryPart.CFrame.X,
							["Z"] = v.PrimaryPart.CFrame.Z,
							["Y"] = v.PrimaryPart.CFrame.Y,
							
							["ORIEN_X"] = v.PrimaryPart.Orientation.X,
							["ORIEN_Z"] = v.PrimaryPart.Orientation.Z,
							["ORIEN_Y"] = v.PrimaryPart.Orientation.Y
						})
					end

Seems good? I don’t really know what kind of feedback you are looking for

1 Like

Yea sorry. Just looking for any kind of feedback

Not necessary, the data service will coerce data passed to write functions into a string format automatically. Using JSONEncode yourself before saving to a DataStore will unnecessary add some bloat to the size of your data. Just save the raw table.

Nothing else to give feedback on. You’ve just provided a for loop that creates a table and stores some values, so not sure what you’re looking for there.

2 Likes

I mean all i would do if it was in my game is localize v.PrimaryPart.CFrame,v.PrimaryPart.Orientation and table.insert for it to be just a tiny bit faster.
So this is what it would look like

local table_insert = table.insert
local v_PrimaryPart_CFrame, v_PrimaryPart_Orientation
for _, v in pairs(FOLDER:GetChildren()) do -- // FOLDER IS WHERE ALL THE MODELS ARE LOCATED
					if v:IsA("Model") then
						--local ON = 0
                        v_PrimaryPart_CFrame = v.PrimaryPart.CFrame
                        v_PrimaryPart_Orientation = v.PrimaryPart.Orientation
						table_insert(DATA_TABLE, {
							["OBJECT"] = v.Name,
							["X"] = v_PrimaryPart_CFrame.X,
							["Z"] = v_PrimaryPart_CFrame.Z,
							["Y"] = v_PrimaryPart_CFrame.Y,
							
							["ORIEN_X"] = v_PrimaryPart_Orientation.X,
							["ORIEN_Z"] = v_PrimaryPart_Orientation.Z,
							["ORIEN_Y"] = v_PrimaryPart_Orientation.Y
						})
					end

It is a overkill for this, but if it is in a loop that would run hundred of times per second, or needs to be fast in general, it would already help