Game not saving player data, datastores broken

Nothing in studio / in-game is being saved when the player leaves. I have received no errors in the output and when I use pcalls to see if there is an error, it doesn’t print the error nor does it print anything if the pcall doesn’t error out. I am not sure if this is a bug on Roblox’s end or if the bug is happening due to an error. I have tried doing prints to see if the game is catching when the player leaves, and I have tried game:BindToClose(function() so that it waits to be processed.

Script:

local Users = game:GetService("Players")
local SodaData = game:GetService("DataStoreService"):GetDataStore("SodaDatas00133443") --SodaData1230, SodaDatas9, SodaDatas111
local PortalData = game:GetService("DataStoreService"):GetDataStore("PortalDatas001334443")
local coinData = game:GetService("DataStoreService"):GetDataStore("CoinDatas22443")
local DiscoData = game:GetService("DataStoreService"):GetDataStore("HasDisco001443")
local MushroomData = game:GetService("DataStoreService"):GetDataStore("MushroomData00143")
local ComputerData = game:GetService("DataStoreService"):GetDataStore("ComputerData00143")
local SugarCaneData = game:GetService("DataStoreService"):GetDataStore("SugarCaneData00143")
local MainFolder = workspace:WaitForChild("Sodas")

Users.PlayerAdded:Connect(function(User)
	local Leader = Instance.new("Folder", User)
	Leader.Name = "leaderstats"
	local Quests = Instance.new("Folder", User)
	Quests.Name = "Quests"
	local Sodas = Instance.new("Folder", User)
	Sodas.Name = "Owned" -- Sodas
	local Owned = Instance.new("IntValue", Leader)
	Owned.Name = "Sodas"
	local Data
	local data2
	local CData
	local DiscoDataB
	local MRData
	local COData
	local SCData
	local Finish, Error = pcall(function()
		Data = SodaData:GetAsync("Data-"..User.UserId)
	end)
	if Finish and Data then
		for _, Soda in pairs(Data) do
			if MainFolder:FindFirstChild(Soda) then
				local Gotten = Instance.new("BoolValue", Sodas)
				Gotten.Name = Soda
				Owned.Value += 1
			end
		end
	end
	
	local suc, err = pcall(function()
		data2 = PortalData:GetAsync("Data-"..User.UserId)
	end)
	if suc and data2 then
		User:WaitForChild("PortalDone").Value = data2
		if User:WaitForChild("PortalDone").Value == true then
			game.ReplicatedStorage.DestroyPortal:FireClient(User)
		end
	end
	
	local success, err2 = pcall(function()
		CData = coinData:GetAsync("Data-"..User.UserId)
	end)
	if success then
		print("Loading plr coins...")
		User:WaitForChild("AvatarCoins"):WaitForChild("ACValue").Value = CData
	else
		print("not working: "..err2)
	end
	
	local succ, er = pcall(function()
		DiscoDataB = DiscoData:GetAsync("Data-"..User.UserId)
	end)
	if succ then
		print("Checking if plr has Disco...")
		User:WaitForChild("HasDisco").Value = DiscoDataB
	else
		print("not working: "..er)
	end
	
	local suxx, er0 = pcall(function()
		MRData = MushroomData:GetAsync("Data-"..User.UserId)
	end)
	if suxx then
		print("Checking if plr has Mushroom...")
		User:WaitForChild("HasMushroom").Value = MRData
	else
		print("not working: "..er0)
	end
	
	local sux, er00 = pcall(function()
		COData = ComputerData:GetAsync("Data-"..User.UserId)
	end)
	if sux then
		print("Checking if plr has Binary...")
		User:WaitForChild("HasBinary").Value = COData
	else
		print("not working: "..er00)
	end
	
	local su, e = pcall(function()
		SCData = SugarCaneData:GetAsync("Data-"..User.UserId)
	end)
	
	if su then
		print("Checking if plr has SC...")
		User:WaitForChild("HasSC").Value = SCData
	else
		print("not working: "..e)
	end
end)

game.Players.PlayerRemoving:Connect(function(User) -- part where the script doesn't save data
	print("test") -- test print
	local Sodas = {}
	local portalDone = User:WaitForChild("PortalDone")
	local DiscoBool = User:WaitForChild("HasDisco")
	local MRBool = User:WaitForChild("HasMushroom")
	local BinaryBool = User:WaitForChild("HasBinary")
	local SCBool = User:WaitForChild("SCBool")

	for _, Soda in pairs(User.Owned:getChildren()) do -- Sodas
		table.insert(Sodas, Soda.Name)
	end
	local Finish, Error = pcall(function()
		SodaData:SetAsync("Data-"..User.UserId, Sodas)
	end)
	if Finish then

	else
		print("not working: "..Error)
	end
	local suc, err = pcall(function()
		PortalData:SetAsync("Data-"..User.UserId,portalDone.Value)
	end)

	local success, err3 = pcall(function()
		coinData:SetAsync("Data-"..User.UserId,User:WaitForChild("AvatarCoins"):WaitForChild("ACValue").Value)
	end)

	if success then
		print("Saving plr coins...")
	else
		print("not working: "..err3)
	end

	local succ, er = pcall(function()
		DiscoData:SetAsync("Data-"..User.UserId,DiscoBool.Value)
	end)

	if succ then
		print("Saving Disco Bool...")
	else
		print("not working: "..er)
	end

	local suxx, er0 = pcall(function()
		MushroomData:SetAsync("Data-"..User.UserId,MRBool.Value)
	end)

	if suxx then
		print("Saving Mushroom Bool...")
	else
		print("not working: "..er0)
	end

	local sux, er00 = pcall(function()
		ComputerData:SetAsync("Data-"..User.UserId,BinaryBool.Value)
	end)

	if sux then
		print("Saving Computer Data...")
	else
		print("not working: "..er00)
	end

	local su, e = pcall(function()
		SugarCaneData:SetAsync("Data-"..User.UserId,SCBool.Value)
	end)

	if su then
		print("Saving SC Data...")
	else
		print("not working: "..e)
	end
end)

game:BindToClose(function()
	wait(2)
	for _, User in pairs(Users:GetPlayers()) do
		local Sodas = {}
		for _, Soda in pairs(User.Owned:getChildren()) do -- Sodas
			table.insert(Sodas, Soda.Name)
		end
		local Finish, Error = pcall(function()
			SodaData:SetAsync("Data-"..User.UserId, Sodas)
		end)
		if Finish then
			
		else
			print(Error)
		end
	end
end)

Would you please show us the output from the prints.

i have since fixed the problem. i had made a typo in the “WaitForChild” and it was giving out an infinite yield because the item that it was waiting on doesnt exist, so it waited on an infinite yield and did not reach the rest of the script or save anything.

1 Like