My Datastore Function saves about 4/5 times in studio. When it doesn’t save I don’t get an error message or a success message. I was wondering, if there was anything wrong with the code?
function SavingData(Player,Kicked,Loaded)
local PlayerData = game.ServerStorage.PlayerData:FindFirstChild(Player.Name)
local PlayerLive = PlayerData.Miscs.PlayerLive
local Key = Player.UserId
local Character = Player.Character
local DataToSave
if Kicked ~= true then
if Loaded ~= false then
print("Stats Saving")
DataToSave = {
PlayerData.Health.Health.Value,
PlayerData.Health.Food.Value,
PlayerData.Health.Hydration.Value,
PlayerData.Health.Energy.Value,
PlayerData.Health.Bleeding.Value,
PlayerData.Health.FoodPoisoning.Value,
PlayerData.Miscs.Money.Value,
PlayerData.Miscs.BankMoney.Value,
PlayerData.Miscs.IntelligenceLevel.Value,
PlayerData.Miscs.IntelligenceXP.Value,
PlayerData.Miscs.State.Value,
PlayerData.Miscs.WantedTime.Value
}
print(DataToSave)
local Success, err = pcall(function()
StatsDataStore:SetAsync(Key, DataToSave)
end)
if not Success then
warn(err)
print("RIP")
--wait()
SavingData(Player)
elseif Success then
warn(Success)
else
warn("Super position")
print("Hold UPPPPP")
end
end
end
end
When it saves successful I get true. But when It doesn’t I get no output from the pcall.
you’re essentially saving the object’s value without stating its name, your output table would look like this {true, false, false, etc}, what you should do is assign them an input value like this…
What exactly are you doing different from when it saves and when it doesn’t save? Do you change something within the pcall to force an error, or what is causing it to fail?
The DataToSave table works perfectly fine. For saving and loading. This function works fine 4/5 times. Its only that 1/5 times it doesn’t work. And when it doesn’t work I don’t get any output. My only though is that the server is shutting down before it has time to save.
try kicking yourself out of the game using player:kick() instead of stopping the gameplay in studio, because sometimes studio stops the game before it even registers that the player left.
I’ve tried on Roblox it self and everything is saving normal. So I think its just a studio Issue were its closing before it can save. I’m just trying to make sure the my Datastore is reliable for my new game.