local DataBaseStore = game:GetService("DataStoreService"):GetDataStore("tng-ds-pesl")
local StatSholder = script.DataTemplate
game.Players.PlayerAdded:Connect(function(NewPlayer)
local Key = "WGK-ID:" .. NewPlayer.userId
local GetSave = DataBaseStore:GetAsync(Key)
local DataBaseFolder = Instance.new("Folder", NewPlayer)
DataBaseFolder.Name = "PlayerData"
for i, StatsFolders in pairs(StatSholder:GetChildren())do
for t, StatNames in pairs(StatsFolders:GetChildren())do
for k, Stats in pairs(StatNames:GetChildren())do
local NewStats = Instance.new(Stats.ClassName)
NewStats.Name = Stats.Name
NewStats.Value = Stats.Value
NewStats.Parent = DataBaseFolder
end
end
end
if GetSave then
for i, StatsFolders in pairs(script.DataTemplate:GetChildren())do
for t, StatNames in pairs(StatsFolders:GetChildren())do
for k, Stats in pairs(StatNames:GetChildren())do
DataBaseFolder[StatsFolders.Name].Value = GetSave[i]
DataBaseFolder[StatNames.Name].Value = GetSave[i]
DataBaseFolder[Stats.Name].Value = GetSave[i]
print(k, StatsFolders.Name, StatNames.Name, Stats.Name, Stats.Value)
end
end
end
else
local StatsToSave = {}
for i, StatsFolders in pairs(DataBaseFolder:GetChildren())do
for t, StatNames in pairs(StatsFolders:GetChildren())do
for k, Stats in pairs(StatNames:GetChildren())do
table.insert(StatsToSave, StatsFolders.Name, StatNames.Name, Stats.Value)
print(k, StatsFolders.Name, StatNames.Name, Stats.Name, Stats.Value)
end
end
end
DataBaseStore:SetAsync(Key, StatsToSave)
end
while wait(30) do
local StatsToSave = {}
for i, StatsFolders in pairs(DataBaseFolder:GetChildren())do
for t, StatNames in pairs(StatsFolders:GetChildren())do
for k, Stats in pairs(StatNames:GetChildren())do
table.insert(StatsToSave, StatsFolders.Name, StatNames.Name, Stats.Value)
print(k, Stats.Name, Stats.Value)
end
end
end
DataBaseStore:SetAsync(Key, StatsToSave)
end
game.Players.PlayerRemoving:Connect(function(OldPlayer)
local Key = "WGK-ID:" .. OldPlayer.userId
local StatsToSave = {}
for i, StatsFolders in pairs(DataBaseFolder:GetChildren())do
for t, StatNames in pairs(StatsFolders:GetChildren())do
for k, Stats in pairs(StatNames:GetChildren())do
table.insert(StatsToSave, StatsFolders.Name, StatNames.Name, Stats.Value)
print(k, Stats.Name, Stats.Value)
end
end
end
DataBaseStore:SetAsync(Key, StatsToSave)
end)
end)
THIS IS THE ERROR I GET 19:37:52.356 - Character is not a valid member of Folder
My script is in ServerStorage, and the DataTemplate is in the script. My Values are in a Folder within a Folder.

1 comment
Or i could just make smaller separate scripts for each folder?