local currencyName = "RebornTokens" 
local DataStore = game:GetService("DataStoreService"):GetDataStore("UC")

game.Players.PlayerAdded:Connect(function(player)
	
	local stats = Instance.new("Folder")
        stats.Name = "leaderstats"
        stats.Parent = player

        local DP = Instance.new("IntValue")
        DP.Name = "Points"
        DP.Parent = stats

        local DR = Instance.new("IntValue")
        DR.Name = "Rolls"
        DR.Parent = stats
	
	local ID = currencyName.."-"..player.UserId
	local savedata = nil
	
	pcall(function()
		savedData = DataStore:GetAsync(ID)
	end)
	
	if savedData ~= nil then
		DP.Value = savedData
		DR.Value = savedData
		print("Data loaded")
	else
		DP.Value = 0 
		DR.Value = 0
		print("New player to the game")
	end
	

end)

game.Players.PlayerRemoving:Connect(function(player)
	local ID = currencyName.."-"..player.UserId
	DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)

game:BindToClose(function()
	
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			player:Kick("This Game is Shutting down for saving data and adding updates plz rejoin :D ")
		end
	end

	wait(5)
	
end)

game.ReplicatedStorage.re.OnServerEvent:Connect(
    function(player)
        player.leaderstats.Rolls.Value += 1
    end
)

The last few bits are for the roll function so dont worry about that

This script is supposed to be saving but for SOME FLIPPIN REASON, EVERY ####### TIME I TRY AND MAKE A SAVE SCRIPT IT NEVER WORKS, I HAVE BEEN DOING FAILING SAVING SCRIPT FOR A MONTH AAAAAAAAAAAAAAAAAAAAAAAAA

and yes api and http services are on

6 comments

0

sorry im angry its just it is taking way too long to do a save script

0

I don't see any Instance named after "currencyName".

0

so i should add == currencyName to the ends of my stats?

0

No, there simply isn't anything that can be found as "RebornTokens". Whichever IntValue that is meant to represent it, just assign it's Name property after the variable.

0

You've also saved only one piece of data, it will load RebornTokens' data to each IntValue. Use an Array to store multiple pieces of data. It is also recommended you use :UpdateAsync() as :SetAsync() overrides any previous data without consideration. You can see it's documentation in the Developer Wiki.

0

ok, can you put it in an answer? Because this comment seems more like an answer with just words with no code to help