I'm making a core defense game and I cant figure out how do save a folder of boolvalues. I have saved the tables, names and values but cannot figure out how to give the value to the player.
C P N
Server Script | ServerScriptService | RoundsManager
local dss = game:GetService("DataStoreService")
local gsave = dss:GetDataStore("GSaves")
local characterSaves = dss:GetDataStore("CharacterSaves")
game.Players.PlayerAdded:Connect(function(plr)
local leader = Instance.new("BoolValue",plr)
leader.Name = "leaderstats"
local Characters = Instance.new("Folder",plr)
Characters.Name = "Characters"
local UFSans = Instance.new("BoolValue",Characters)
UFSans.Name = "UFSans"
local G = Instance.new("IntValue",leader)
G.Name = "G"
local gdata
local characterdata
local success,errormessage = pcall(function()
characterdata = characterSaves:GetAsync(plr.UserId.."-Characters")
gdata = gsave:GetAsync(plr.UserId.."-G")
end)
if success and gdata and characterdata then
print("Got "..plr.Name.."'s data!")
plr.leaderstats.G.Value = gdata
else
print("Failed to save "..plr.Name.."'s data!")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success,errormessage = pcall(function()
gsave:SetAsync(plr.UserId.."-G",plr.leaderstats.G.Value)
local characterValues = {}
for i,CharacterName in pairs(plr.Characters:GetChildren()) do
table.insert(characterValues, CharacterName, CharacterName.Value)
end
characterSaves:SetAsync(plr.UserId.."-Characters",characterValues)
end)
if success then
print("Saved "..plr.Name.."'s data!")
else
print("Failed to save "..plr.Name.."'s data!")
warn(errormessage)
end
end)
