I've been trying to do this for a while now, but nothing has seemed to work. I cannot think of anything else to try.
local DataStore = game:GetService("DataStoreService"):GetGlobalDataStore("SaveSlotsTest")
game.Players.PlayerAdded:Connect(function(Player)
local Folder = Instance.new("Folder",Player)
Folder.Name = "PlayerStorage"
local Slot1 = Instance.new("Folder",Folder)
Slot1.Name = "Slot1"
local Slot2 = Instance.new("Folder",Folder)
Slot2.Name = "Slot2"
local Val = Instance.new("IntValue",Folder)
Val.Name = "Test1"
local Val2 = Instance.new("IntValue",Folder)
Val2.Name = "Test2"
local Val3 = Instance.new("IntValue",Folder)
Val3.Name = "Test3"
local Stats = {Val,Val2,Val3}
local Slots = {Slot1,Slot2}
local newstat = nil
for i, slot in pairs(Slots) do
for i, stat in pairs(Stats) do
newstat = stat:Clone()
stat:Destroy()
newstat.Parent = slot
end
end
local Stats = DataStore:GetAsync(Player.UserId)
if Stats ~= nil then
newstat.Value = Stats[1]
else
newstat.Value = nil
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local SaveData = {}
for i,v in pairs(Player.PlayerStorage:GetDescendants()) do
table.insert(SaveData,v)
end
DataStore:SetAsync(Player.UserId, game:GetService("HttpService"):JSONEncode(SaveData))
end)

6 comments
Right, should I put that outside of the PlayerRemoving function, or put it inside? and if outside, how should I define the player?
I added this onto the script, but it doesn't seem to work.
When the game is closing, loop through all the players and save their data
Right, I've made a script for that and it doesn't seem to be working. I'll post it here.
k
Posted.