PCall function not working?

Hi guys,

I use pcalls for a few things in my game. Most recently I added DataStore, which uses pcall a couple of times.

When saving into my datastore, on `PlayerRemoving’, I use a pcall to check for the save.

	local PlayerID = "Player_"..player.UserId
	print("removing check")
	local save = {
		Coins = player.leaderstats.Coins.Value;
		Stage = player.leaderstats.Stage.Value

	local suc, err = pcall(function()
		CurrentDS:SetAsync(PlayerID, save)
		print("save check")
	if suc then
		print("Data Saved")
		print("Error during save")

However, my datastore is not saving for some reason. The “removing check” prints, but everything below and in the pcall does not print.

Is there an issue with my function that I am not noticing, or is there something else going on that I am not understanding?

Are you using game:BindToClose? Maybe the server is closing before saving the data.


Try testing it in an actual game and not in studio, or adding a wait before connecting the player removing function. Also print(err) to see if there is an error message.

1 Like