So I have a script that contains a large amount of player values, and I need a way to save all of the values when the player leaves, and call on those values when they rejoin. I know if I wanted to, I could just individually for each one have a line that saves them, however this seems highly inefficient and I was wondering if there was a better way to go about it.
Script that creates the values:
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local teamXP = Instance.new("Folder")
teamXP.Name = "teamXP"
teamXP.Parent = leaderstats
local CD = Instance.new("IntValue")
CD.Name = "Class-D"
CD.Value = 0
CD.Parent = teamXP
local FP = Instance.new("IntValue")
CD.Name = "Foundation Personel"
CD.Value = 0
CD.Parent = teamXP
local ScD = Instance.new("IntValue")
ScD.Name = "Scientific Department"
ScD.Value = 0
ScD.Parent = teamXP
local MD = Instance.new("IntValue")
MD.Name = "Medical Department"
MD.Value = 0
MD.Parent = teamXP
local SD = Instance.new("IntValue")
SD.Name = "Security Department"
SD.Value = 0
SD.Parent = teamXP
local EC = Instance.new("IntValue")
EC.Name = "Ethics Comittee"
EC.Value = 0
EC.Parent = teamXP
local DEA = Instance.new("IntValue")
DEA.Name = "Department of External Affairs"
DEA.Value = 0
DEA.Parent = teamXP
local RRT = Instance.new("IntValue")
RRT.Name = "Rappid Response Team"
RRT.Value = 0
RRT.Parent = teamXP
local ISD = Instance.new("IntValue")
ISD.Name = "Internal Security Department"
ISD.Value = 0
ISD.Parent = teamXP
local IA = Instance.new("IntValue")
IA.Name = "Intelligence Agency"
IA.Value = 0
IA.Parent = teamXP
local O5 = Instance.new("IntValue")
O5.Name = "O5 Council"
O5.Value = 0
O5.Parent = teamXP
local CI = Instance.new("IntValue")
CI.Name = "Chaos Insurgency"
CI.Value = 0
CI.Parent = teamXP
end)