-
What do you want to achieve?
I want to make a Datastore that takes values in a folder and saves all the values. -
What is the issue?
It doesn’t save the values that are in the folder. -
What solutions have you tried so far?
I saw the forum post similar to this one but it didn’t help me fix my problem.
local Datastore = game:GetService("DataStoreService")
local MyDataStore = Datastore:GetDataStore("MyDataStore")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
Players.PlayerAdded:Connect(function(Player)
local PlayerData = ServerStorage:WaitForChild("PlayerData"):Clone()
PlayerData.Parent = Player
local SavedData = {}
for i, v in pairs(PlayerData:GetChildren()) do
table.insert(SavedData, v)
end
for i, v in pairs(PlayerData:GetChildren()) do
local Data = MyDataStore:GetAsync(Player.UserId..SavedData[i].Name)
v.Value = Data
end
end)
Players.PlayerRemoving:Connect(function(Player)
local PlayerData = Player:WaitForChild("PlayerData")
local SavedData = {}
for i, v in pairs(PlayerData:GetChildren()) do
table.insert(SavedData, v)
end
for i, v in pairs(SavedData) do
MyDataStore:SetAsync(Player.UserId..SavedData[i].Name, SavedData[i].Value)
end
end)