Need assistance switching from datapersistence to datastoreservice

Provide an overview of:

What does the code do and what are you not satisfied with?

  • For quite a while I have been leaving a message in my output saying that DataPersistence is deprecated, though I have not managed to patch the error as it hadn’t really been on my mind, thus I don’t know how to switch from the deprecated version to datastoreservice

What potential improvements have you considered?

  • Asking DevForum, Googling or basically just asking for informative feedback or code patchment from other scripters

How (specifically) do you want to improve the code?

  • I want to switch from DataPersistence to DatastoreService to make my game save my stats again
--Leaderboard script by BCGames
--Further Modded By Rescm2b

Use_DP = true --If you want the game to save your
							  --stats then set this to true

function saveStat(plr,val,key)
	if plr then
		plr:WaitForDataReady()
		plr:SaveNumber(key,val)
	end
end

function loadStat(plr,key,stat)
	if plr then
		plr:WaitForDataReady()
		stat.Value = plr:LoadNumber(key,stat)
	end
end

game.Players.PlayerAdded:connect(function(player)
	Stat = Instance.new("IntValue",player)
	Stat.Name = "leaderstats"
	Kills = Instance.new("IntValue",Stat)
	Kills.Name = "Kills"
	Deaths = Instance.new("IntValue",Stat)
	Deaths.Name = "Deaths"
	if Use_DP then
		loadStat(player,"Kills",Kills)
		loadStat(player,"Deaths",Deaths)
	end
	player.CharacterAdded:connect(function(char)
		char.Humanoid.Died:connect(function()
			wait(0.05)
			Deaths.Value = Deaths.Value + 1
			if Use_DP then
				saveStat(player,Deaths.Value,"Kills")
			end
			Cre = char.Humanoid:FindFirstChild("creator")
			if Cre then
				if Cre.Value then
					if Cre.Value ~= player then
						Cre.Value.leaderstats.Kills.Value = Cre.Value.leaderstats.Kills.Value +1
					else
						Kills.Value = Kills.Value -1
					end
					if Use_DP then
						saveStat(Cre.Value,Cre.Value.leaderstats.Kills.Value,"Kills")
						saveStat(player,Kills.Value,"Kills")
					end
				end
			end
		end)
	end)
end)

Btw this is a modified script from the toolbox, probably from year <2018.

Thanks in advance!
Mathe

1 Like

P.S All I want is to change the LoadNumber() and SaveNumber() As I think that is what causes the problem

1 Like