No errors are showing in the code but still the data won't save. I added the print each stage to figure out if if there was a error before but it seems just to be the saving part. The print after the saving would work but just doesn't save for some odd reason. I have the API on if you're wondering Here's the code:

local datastore = game:GetService("DataStoreService")
local MyDataStore = datastore:GetDataStore("MyDataStore")

game.Players.PlayerAdded:Connect(function(players)
	local Stats = Instance.new("Folder")
	Stats.Name = "Stats"
	Stats.Parent = players
	
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = Stats
	
	local XP = Instance.new("IntValue")
	XP.Name = "XP"
	XP.Parent = Stats	
	
	local Level = Instance.new("IntValue")
	Level.Name = "Level"
	Level.Parent = Stats
	print ("Stat loaded")
	
	local PlayerID = "SubjectID: "..players.UserId
	local data
	local Sucess, Errormessage = pcall(function()
		 data = MyDataStore:GetASync(PlayerID)
	end)
	if Sucess then
		Cash.Value = data
	end
	
end)
print ("Stat Got")
game.Players.PlayerRemoving:Connect(function(players)
	local PlayerID = "SubjectID: "..players.UserId
	
	local data = players.Stats.Cash.Value
	
	local Sucess, Errormessage = pcall(function()
		MyDataStore:SetAsync(PlayerID, data)
	end)
	
	if Sucess then
		print ("Data was saved!")
	else
		print ("There was an error when saving!")
		warn(Errormessage)
	end
end)


Here is a screenshot of the explorer: https://prnt.sc/uagls1 No error shows in the Output

1 comment

0

GetASync? It's GetAsync xD (line 25)