Data is not saving. Why?

  1. What do you want to achieve?
    I’m simply trying to create a data storage system for my game. I’ve tried many different solutions, however, none of them appear to be working.

  2. What is the issue?
    The issue is that I can’t find the problem with the code. I was hoping some of you could take a look at it and tell me what I’m doing wrong.

  3. What solutions have you tried so far?
    I’ve looked for solutions everywhere however none of them appear to be working. I’m convinced the problem has to do with my code (of course it is). I’ve already tried changing where the data was being stored (from Lighting to ReplicatedStorage), but still no luck.

In order to save the Data, I have created 2 scripts, one for creating the data, and one for saving it. Take a look, please.

– Here is the first script that creates the data (This is only a portion of the script, the parts I thought were necessary. If you need to see more of the script let me know.) –


--Create Leaderstats folder--

		local Leaderstats ="Folder", game.ReplicatedStorage)
		Leaderstats.Name = plr.Name
		local Leaderstats = game.ReplicatedStorage:WaitForChild(plr.Name)

--Create values inside of folder--

		local Points ="NumberValue", Leaderstats)
		Points.Name = ("Points")
		Points.Value = 0
		local Level ="NumberValue", Leaderstats)
		Level.Name = ("Level")
		Level.Value = 1

		local UnlockKeys ="IntValue", Leaderstats)
		UnlockKeys.Name = ("UnlockKeys")
		UnlockKeys.Value = 0

		local TotalMissionsCompleted ="IntValue", Leaderstats)
		TotalMissionsCompleted.Name = ("TotalMissionsCompleted")
		TotalMissionsCompleted.Value = 0


– Here is the second script that saves the data to DataStorage (This one is the WHOLE script.)–

-- Script will be used to save player's data --

local DataStorage = game:GetService("DataStoreService"):GetDataStore("SaveData")

	local PlayerId = ("Player-".. Player.UserId)
	local SaveLevel = game.ReplicatedStorage:WaitForChild(Player.Name):WaitForChild("Level")
	local SavePoints = game.ReplicatedStorage:WaitForChild(Player.Name):WaitForChild("Points")
	local SaveMissionsCompleted = game.ReplicatedStorage:WaitForChild(Player.Name):WaitForChild("TotalMissionsCompleted")
	local SaveUnlockKeys = game.ReplicatedStorage:WaitForChild(Player.Name):WaitForChild("UnlockKeys")
	local GetData = DataStorage:GetAsync(PlayerId)
	if GetData then
		SaveLevel.Value = GetData[1]
		SavePoints.Value = GetData[2]
		SaveMissionsCompleted.Value = GetData[3]
		SaveUnlockKeys.Value = GetData[4]
		local Savings = {SaveLevel.Value, SavePoints.Value, SaveMissionsCompleted.Value, SaveUnlockKeys.Value}
		DataStorage:GetAsync(PlayerId, Savings)

	DataStorage:SetAsync("Player-".. Player.UserId, {game.ReplicatedStorage:WaitForChild(Player.Name):WaitForChild("Level").Value,game.ReplicatedStorage:WaitForChild(Player.Name):WaitForChild("Points").Value,game.ReplicatedStorage:WaitForChild(Player.Name):WaitForChild("TotalMissionsCompleted").Value,game.ReplicatedStorage:WaitForChild(Player.Name):WaitForChild("UnlockKeys").Value})


Thank you so much to anyone who helps. :slight_smile:

  • Zipps

your trying to concate a number with a string and you cant save an array to a datastore, it must be string.

Thanks for the reply minimic2002,
How do you recon I change my code? I haven’t received any errors from the output so where should I start?

You need to see if the data is not nil like so:

if GetData ~= nil then
		SaveLevel.Value = GetData[1]
		SavePoints.Value = GetData[2]
		SaveMissionsCompleted.Value = GetData[3]
		SaveUnlockKeys.Value = GetData[4]

Well id say look at the API for datastores so you can see them broken down.
Then look into string manipulation.
Better string manipulation means you can easily save and read your data.

To fix player
SetAsync(“Player-”… tostring(Player.UserId),Data)

Then for the data if you are trying to save multiple things combine them with table.concat(Table,Seperator). This mean that your table can be turned into 1 string that can be saved. Then to turn it back into string all you have to do is string.split()

I’ll give it a look, thank you.

Are you sure this is the problem? I’m getting no errors in my output.

Try turning it all into 1 string and saving it that way, if that doesn’t work then ill be shocked.

It might also be worth using pcall() to catch errors as datastores can fail sometimes