I was working on a multiple stat saving system for my game, and this is what it turned out:
local datastore = game:GetService("DataStoreService"):GetDataStore("BronzeDarkRPstats")
game:GetService("Players").PlayerAdded:Connect(function(plr)
local playerGui = plr.PlayerGui
local cash = Instance.new("IntValue")
cash.Parent = plr
cash.Name = 'Cash'
cash.Value = 10000
local karma = Instance.new("IntValue")
karma.Parent = plr
karma.Name = 'Karma'
local printersPurchased = Instance.new("IntValue")
printersPurchased.Parent = plr
printersPurchased.Name = "PrintersPurchased"
local job = Instance.new("StringValue")
job.Parent = plr
job.Name = "Job"
local payment = Instance.new("IntValue")
payment.Parent = plr
payment.Name = "Payment"
plr.CharacterAdded:Connect(function(char)
local flagged = Instance.new("BoolValue")
flagged.Parent = char
flagged.Name = "Flagged"
flagged.Value = false
local nametag = game.ReplicatedStorage.Misc.Nametag:Clone()
nametag.Parent = char:WaitForChild("Head")
nametag.Person.Text = plr.Name
job.Changed:Connect(function(val)
nametag.Job.Text = "["..val.."]"
end)
flagged.Changed:Connect(function(val)
if val == true then
nametag.Person.TextColor3 = Color3.fromRGB(255,0,0)
elseif val == false then
nametag.Person.TextColor3 = Color3.fromRGB(255,255,255)
end
end)
end)
local data
local success,failure = pcall(function()
data = datastore:GetAsync(plr.UserId)
end)
if success and data then
plr.Cash.Value = data.cash
plr.Karma.Value = data.karma
print("successfully loaded data")
elseif failure and not success then
print(failure)
warn('data did not load')
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(plr)
for i,v in pairs(workspace:GetDescendants()) do
if v.Name == plr.Name.."_Item" then
v:Destroy()
end
end
local playerGui = plr:WaitForChild("PlayerGui")
local dataTable = {}
dataTable.cash = plr.Cash.Value
dataTable.karma = plr.Karma.Value
local success,failure = pcall(function()
datastore:SetAsync(plr.UserId,dataTable)
end)
if success then
print('data saved')
elseif failure and not success then
print(failure)
warn('data failed to save')
end
end)
However, the output does not display the "data saved", leading me to believe that saving did NOT save.
Did I do something wrong?

1 comment
Try using clonetrooper's datastore editor to see the values.