Is this script not saving or is it my wifi?

Here is my code.

Code:

local ds = game:GetService("DataStoreService"):GetDataStore("SplitsDataStore")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.UserId
	local save1 = plr.leaderstats.Splits
	
	local GetSaved = ds:GetAsync(plrkey)
	if GetSaved then
		save1.Value = GetSaved[1]
	else
		local NumberForSaving = {save1.Value}
		ds:GetAsync(plrkey,NumberForSaving)
	end
end) 

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.UserId, {plr.leaderstats.Splits.Value})
end)

I feel like its just the servers. It saves sometimes, not everytime, but sometimes. It does succesfully load data, but the problem is saving, it is so weird. Sometimes it does, others it doesn’t.

1 Like

Is this only in studio, or does it happen in a live server? You could create an event on game:BindToClose() to iterate the players and save their data like PlayerRemoving is.

Never really tested it in-game, but I think just studio.