Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does DataStores/Leaderstats not saving?

I'd like to answer this question because a lot of people keep asking me about it, here are the reasons

1: It must be a server sided script, not a local script, local scripts save locally and do not update to the server.

2: This script must be placed within serverscriptservice or workspace.

3: The player data must save under the player's ID, and not their username.

4: It must load the data when the player enters the game, and save it when the player leaves the game. Here is an example.

local function onPlayerJoin(player)  -- Runs when players join
--blah blah make your stats and save it under a folder

local playerUserId = "Player_" .. player.UserId  --Gets player ID

	local data = playerData:GetAsync(playerUserId)  --Checks if player has stored data

	if data then

   -- blah blah tell it what to do

local function onPlayerExit(player)  --Runs when players exit

local success, err = pcall(function()

		local playerUserId = "Player_" .. player.UserId

		playerData:SetAsync(playerUserId, player_stats) --Saves player data

	end)

-- blah blah and end, of course I did miss some steps, this is just a rough example.

By the way some people tell me that their values are not next to their name, if the file is not named leaderstats, then it will be saved as a unseen values.

Unseen values are still savable, and still can be accessed the same way.

I hope this helped some people that have this problem!

2 answers

Add a Simple Check on line 19 and see if it prints

if success then
 print("Data Saved")
end

If it doesnt print then it might not have anoth time to Save or what ive noticed with saving on leaving is if your not in the Game for Long Anoth roblox doesnt bother saving the data so wait around a minute and see if that works.

This discussion is preserved as it was. New answers, comments, and votes are closed.