I'm trying to get a save/load system using DataStore on models. I'm not sure if I am doing this correctly. I've read the Wiki article for DataStore as well as multiple Youtube tutorials and applied it somewhat in this script but I don't know what else to do.
**Contact me on Discord's ScriptingHelpers channel
Every time, the outcome is "New "..player.Name.." Data" and in the number checklist in the second function, it always prints "1" What am I doing wrong?
local Players = game:GetService('Players')
local DataStore = game:GetService('DataStoreService')
local PlayerData = DataStore:GetDataStore('PlayerData')
Players.PlayerAdded:connect(function(player)
local Old = PlayerData:GetAsync('Build')
if Old then
local stable = {};
local list = game.Workspace.CookieSheets['CookieSheet'..player.Name]:GetChildren()
for i=1,#list do
stable[i] = {list[i].Name,{list[i]:GetPrimaryPartCFrame():components()}};
end;
PlayerData:SetAsync('Build', stable);
else
print('New '..player.Name..' Data')
end
end)
Players.PlayerRemoving:connect(function(player)
print('1')
local Old = PlayerData:GetAsync('Build')
if Old then
print('2')
local stable = Old
local ModelsContainer = Instance.new("Folder",player)
ModelsContainer.Name = "ModelHolder"
for i=1,#stable do
print('3')
local nm = ModelsContainer[stable[i][1]]:Clone();
nm.Parent = player
nm.CFrame = CFrame.new(unpack(stable[i][2]))
end
end
end)
