I am needing help to make this script have multiple tables (Like local statstoadd) and multiple folders being made in the player. I currently have multiples of the script for each catagory but it is causing data warnings and I am hoping that if I run everything in the one script It will stop the warnings.
local ds = game:GetService("DataStoreService"):GetDataStore("APBeta") -- Replace "DataName" with your Data store name you want.
local StatsToAdd = { -- Add or remove stats, You can also set the default start value too.
["VacationLei"] = 0,
["BlueTie"] = 0,
["RedTie"] = 0,
["BlackTie"] = 0,
["ShellBucket"] = 0,
["VipShellBucket"] = 0, --Vip
["DiamondArrow"] = 0, --Chest
["DiamondRing"] = 0, --Chest
["WizardWand"] = 0, --Chest
}
--// Functions
game.Players.PlayerAdded:Connect(function(plr)
local Prefix = plr.UserId
local BodyAcc = Instance.new("Folder", plr)
BodyAcc.Name = "BodyAcc"
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", BodyAcc) -- 2nd Parameter is the Parent of the instance.
NewInst.Name = i
NewInst.Value = v
end
local Data = nil
pcall(function()
Data = ds:GetAsync(Prefix)
end)
if Data ~= nil then
for i,v in pairs(BodyAcc:GetChildren()) do
v.Value = Data[v.Name]
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Prefix = plr.UserId
local BodyAcc = plr.BodyAcc
pcall(function()
if BodyAcc then
local SaveData = {}
for i,v in pairs(BodyAcc:GetChildren()) do
SaveData[v.Name] = v.Value
end
ds:SetAsync(Prefix, SaveData)
end
end)
end)