Randomly when I was trying to encode boats into my game I realize that whenever I would go in to test the buying system my money would always be set back to whatever it was. There are no errors when saving/loading as It prints the message it should when it is successful
local remote = game:GetService("ReplicatedStorage"):WaitForChild("QuestRemote")
local data = game:GetService("DataStoreService")
local my_data = data:GetDataStore("my_data")
game.Players.PlayerAdded:Connect(function(player)
--for stats
local gold
local level
local exp
-- for quest stuff
local QuestTitle
local QuestTask
local QuestObjective
local QuestProgress
local QuestGold
local QuestExp
--to tell if the boat is bought or not
local schooner_ship
local sucess, errormessage = pcall(function()
gold = my_data:GetAsync(player.UserId.."-gold")
level = my_data:GetAsync(player.UserId.."-level")
exp = my_data:GetAsync(player.UserId.."-exp")
QuestTitle = my_data:GetAsync(player.UserId.."-QuestTitle")
QuestTask = my_data:GetAsync(player.UserId.."-QuestTask")
QuestObjective = my_data:GetAsync(player.UserId.."-QuestObjective")
QuestProgress = my_data:GetAsync(player.UserId.."-QuestProgress")
QuestGold = my_data:GetAsync(player.UserId.."-QuestGold")
QuestExp = my_data:GetAsync(player.UserId.."-QuestExp")
schooner_ship = my_data:GetAsync(player.UserId.."-schooner_ship")
end)
if sucess then
print("data sucessfully loaded")
player.stats.Gold.Value = gold
player.stats.Level.Value = level
player.stats.Exp.Value = exp
player.QuestInformation.QuestTitle.Value = QuestTitle
player.QuestInformation.QuestTask.Value = QuestTask
player.QuestInformation.QuestObjective.Value = QuestObjective
player.QuestInformation.QuestProgress.Value = QuestProgress
player.QuestInformation.QuestGold.Value = QuestGold
player.QuestInformation.QuestExp.Value = QuestExp
player.Boats_bought.schooner_ship.Value = schooner_ship
if QuestTitle == "Default" then
--does nothing if the title is default
else
remote:FireClient(player, "TransferBritish")
end
else
print("there was an error getting your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
--for all stats
local sucess, errormessage = pcall(function()
my_data:SetAsync(player.UserId.."-gold", player.stats.Gold.Value)
my_data:SetAsync(player.UserId.."-level", player.stats.Level.Value)
my_data:SetAsync(player.UserId.."-exp", player.stats.Exp.Value)
-- for quest progression
my_data:SetAsync(player.UserId.."-QuestTitle", player.QuestInformation.QuestTitle.Value)
my_data:SetAsync(player.UserId.."-QuestTask", player.QuestInformation.QuestTask.Value)
my_data:SetAsync(player.UserId.."-QuestObjective", player.QuestInformation.QuestObjective.Value)
my_data:SetAsync(player.UserId.."-QuestProgress", player.QuestInformation.QuestProgress.Value)
my_data:SetAsync(player.UserId.."-QuestGold", player.QuestInformation.QuestGold.Value)
my_data:SetAsync(player.UserId.."-QuestExp", player.QuestInformation.QuestExp.Value)
my_data:SetAsync(player.UserId.."-schooner_ship", player.Boats_bought.schooner_ship.Value)
end)
if sucess then
print("data successfully saved!")
else
print("there was an error saving data")
warn(errormessage)
end
end)
I did go into server-side while coding to give myself money so maybe that could be the issue but I've never had a problem like that previously

1 comment
You didn’t make the stats dolder in the player. Make the stats folder in PlayerAdded