#What could we do
Save the data as a Table, but not a regular table, a Dictionary. Tables can also save tables inside of them.
#Tables
You probably already know how to make Tables and Dictionaries
local table = {"I am a table", false, "you are a string", 231}
local dictionary = {["Tintinnabulation"] = "The ringing sounds in your ears",
["Abecedarian"] = "Beginner",
["LordDragonZord"] = "English grades are bad but would rather learn English than math."}
Here's the difference between tables and dictionaries. Tables have iterators already set for them which is 1-#table (1 through the number of values in the table). The iterators for dictionaries are set by you. Meaning you can have custom iterators. Another thing is if you want to add values to them you do them in different ways:
table.insert(Table, "Foo")
dictionary["And I would walk 500 miles"] = "and I would walk 500 more"
table[1] = "and I would walk 1000 miles, to see your face just passing by"
#Final Product
This is what your script should look like, this is like the blue prints. Base your script off this one.
local ds = game:GetService("DataStoreService"):GetDataStore("Drawing")
local datatobesaved = {"BrickColor", "Size", "CFrame"}
function setplyrdata(objs, id)
local table = {}
for _,p in pairs(objs:GetChildren()) do
table[p.Name] = {}
for _,prop in pairs(datatobesaved) do
table[p.Name][prop] = p[prop]
end
end
end
return table
end
game:GetService("Players").PlayerAdded:connect(function(plyr)
local plyrdata = ds:GetAsync(plyr.userId)
local palate = workspace.PlayersBlocks
if plyrdata then
for i,v in pairs(plyrdata) do
for _,p in pairs(palate:GetChildren()) do
if p.Name == i then
for prop,val in pairs(v) do
p[prop] = val
end
end
end
end
else
ds:SetAsync(plyr.userId, setplyrdata(palate, plyr.userId))
end
end)
Hope it helps!(Edit the final product to match your script)
1 comment
Extremely useful answer, thanks! I will attempt to adapt this for what I need, as I didn't specify exactly what I needed. Is it OK if I can message you in regard to this post later on, with more detail on certain situations? :) seriously useful answer thought, thanks