DataStore not saving, Not getting an error or success message

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.

1 Like

Are you sure you don’t get an output? I tested your code and got the error message in the err variable as expected.

This is the output when everything is fine. Both Datastores save.

Bug Success

This is the output when it doesn’t save. There’s no output just blank.

Bug No Error

i think you’re saving values without assigning them a name / code like

DataToSave = {
				PlayerData.Health.Health.Value,
				PlayerData.Health.Food.Value,

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…

DataToSave = {
				PlrHealth = PlayerData.Health.Health.Value,
				PlrFood = PlayerData.Health.Food.Value,

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 tried doing that in studio but I got the same result. I will do the same test but on Roblox and see if I get the same result.

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.

are u using bind to close because u need that for studio other wise

this is what bind to close should be like, note u need two functions

game:BindToClose(function()
	for _, Player in pairs(game.Players:GetPlayers()) do
		
boring bits
  local playerId = Player.Name.."[|]"..Player.UserId

  -- Saving Clicks
  local clicksValue = Player.leaderstats2.Clicks.Value
  local succes, errormessage = pcall(function()
  	clicksDataStore:SetAsync(playerId, clicksValue)
  end)

  -- Saving Rebirths 
  local rebirthsValue = Player.leaderstats2.Rebirths.Value

  local succes, errormessage = pcall(function()
  	rebirthsDataStore:SetAsync(playerId, rebirthsValue)	
  end)

  -- Saving Gems
  local gemsValue = Player.leaderstats2.Gems.Value

  local succes, errormessage = pcall(function()
  	gemsDataStore:SetAsync(playerId, gemsValue)	
  end)
  
  -- Saving Omegas
  local OmegasValue = Player.leaderstats2.Omegas.Value
  local succes, errormessage = pcall(function()
  	gemsDataStore:SetAsync(playerId, gemsValue)	
  end)

end
end)

and above that i have my normal

-- Saving Data 
game.Players.PlayerRemoving:Connect(function(player)

more boring bits
	
	local succes, errormessage = pcall(function()
		OmegaDataStore:SetAsync(playerId, OmegaValue)	
	end)
end)

i haven’t had a single data loss since, in studio or roblox.exe

Thanks a lot for this. I think this is the issue. I will try it out, and test it.

1 Like

No problem i had the exact same issue and spent 2 weeks tearing my hair out in frustration LOL

FerdinandMatadorAngryRipsHairGIF

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.