I recently had a dataleak on my game and need to make the game use datastore2, I would like the use the old way of saving (a folder and values are made with a table) how would I make this save to datastore 2?
script:
local ds = game:GetService("DataStoreService"):GetDataStore("APCharmBETATESTING") -- Replace "DataName" with your Data store name you want.
local StatsToAdd = { -- Add or remove stats, You can also set the default start value too.
["Beta"] = 0,
["Pizza"] = 0,
["Boba"] = 0,
["Pinata"] = 0,
["Donut"] = 0,
["Flower"] = 0,
["LifeRing"] = 0,
["Coins"] = 0,
["Shell"] = 0,
["Starfish"] = 0,
["Turtle"] = 0,
}
--// Functions
game.Players.PlayerAdded:Connect(function(plr)
local Prefix = plr.UserId
local Charm = Instance.new("Folder", plr)
Charm.Name = "Charm"
for i,v in pairs(StatsToAdd) do -- This will automate the Table for us so we don't need to use Instance alot and changing Values.
local NewInst = Instance.new("IntValue", Charm) -- 2nd Parameter is the Parent of the instance.
NewInst.Name = i
NewInst.Value = v
end
local Data = nil
pcall(function()
Data = ds:SetAsync(Prefix)
end)
if Data ~= nil then
for i,v in pairs(Charm:GetChildren()) do
v.Value = Data[v.Name]
end
end
print("Loading Charm")
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Prefix = plr.UserId
local Charm = plr.Charm
pcall(function()
if Charm then
local SaveData = {}
for i,v in pairs(Charm:GetChildren()) do
SaveData[v.Name] = v.Value
end
ds:UpdateAsync(Prefix, SaveData)
end
end)
end)