shared.DataStore = game:GetService("DataStoreService")
shared.DataKeyID = shared.DataStore:GetDataStore("4Alpha")
local DataLoaded = {}
game.Players.PlayerAdded:Connect(function(plr)
-- DATA CREATE/LOAD
local subData
local Succes, Value = pcall(shared.DataKeyID.GetAsync, shared.DataKeyID, "Key-"..plr.UserId)
if Succes == false then plr:Kick("Your data has been safely saved. Some Gameplay problems may have occured... Try joining again.") return end
local data = Value or {}
print("Data Loaded: ", data)
for _, child1 in game.ServerStorage.DataStores:GetChildren() do
if child1:IsA("BoolValue") then
local clone = child1:Clone()
clone.Parent = plr
clone.Value = data[child1.Name] or child1.Value
end
if child1:IsA("Folder") then
subData = data[child1.Name] or {}
local clone = child1:Clone()
for _, child2 in clone:GetChildren() do
if child2:IsA("NumberValue") or child2:IsA("StringValue") or child2:IsA("IntValue") then
child2.Value = subData[child2.Name] or child2.Value
else
subData[child2.Name] = subData[child2.Name] or {}
for _, value in child2:GetDescendants() do
if value:IsA("IntValue") or value:IsA("StringValue") then
value.Value = subData[child2.Name][value.Name] or value.Value
end
end
end
end
clone.Parent = plr
end
end
DataLoaded[plr] = true
end)
#Non coding change-DataStore
1 messages · Page 1 of 1 (latest)
game.Players.PlayerRemoving:Connect(function(plr)
if DataLoaded[plr] == nil then return end
local data = {}
local subData
for _, child1 in plr:GetChildren() do
if child1:IsA("BoolValue") then
data[child1.Name] = child1.Value
end
if child1:IsA("Folder") then
subData = {}
for _, child2 in plr[child1.Name]:GetChildren() do
if child2:IsA("NumberValue") or child2:IsA("StringValue") or child2:IsA("IntValue") then
subData[child2.Name] = child2.Value
elseif child1:IsA("Folder") then
subData[child2.Name] = {}
for _, value in child2:GetDescendants() do
if value:IsA("IntValue") or value:IsA("StringValue") then
subData[child2.Name][value.Name] = value.Value
end
end
end
end
data[child1.Name] = subData
plr[child1.Name]:Destroy()
end
end
local Succes, value = pcall(shared.DataKeyID.SetAsync, shared.DataKeyID, "Key-"..plr.UserId, data)
print("Saved Data:", data)
DataLoaded[plr] = nil
end)
game:BindToClose(function()
while next(DataLoaded) ~= nil do
task.wait()
end
end)
Create your own, by Naming/Creating a folder to "DataStores" in "ServerStorage"
Non code-DataStore