Datastore Issue

So I have my datastore all perfectly made with API turned on, except it will not run properly. This might be a bug, but I put it here just in case I missed some update with datastores or something. Team create is off and this is a group game for extra information.

Script
local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("Name Here")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
 
	local cash = Instance.new("IntValue")
	cash.Name = "Boos"
	cash.Parent = leaderstats
 
	local data
	local success, errormessage = pcall(function()
 		data = myDataStore:GetAsync(player.UserId.."-cash")
	end)
 
	if success then
 		cash.Value = data
	else
 		print("There was a error with getting your data")
 		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
 
	local success, errormessage = pcall(function()
 		myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Boos.Value)
	end)
 
	if success then
 		print("Player Data Successfully Saved")
	else
 		print("There was an error when saving data")
		warn(errormessage)
	end
end)

I also have HTTP Service turned on, but it didn’t affect anything before, so it shouldn’t be a problem.
No errors/prints show up in the output as well.

Thanks For Reading! :grin:

1 Like

Now it is saving?!?! can anyone explain to me what happened? I never was close to hitting the datastore limit. :thinking:

If the issue is happening when there is only one player in the server and they leave I suggest using this feature, it will keep the server open for another 30 seconds so the function can be executed. https://developer.roblox.com/en-us/api-reference/function/DataModel/BindToClose

1 Like
2 Likes