DataStore problem

I was adding settings to my DataStore script, when all of a sudden, it erased all my data and doesn’t save anything. There were no errors or warnings.

This is my script

local Players = game:GetService('Players')
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")

local function OnPlayerAdded(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local nonleaderstats = Instance.new("Folder", player)
	nonleaderstats.Name = "nonleaderstats"

	local rank = Instance.new("StringValue", leaderstats)
	rank.Name = "Rank"
	rank.Value = player:GetRoleInGroup(16597728)

	local Coins = Instance.new("IntValue", nonleaderstats)
	Coins.Name = "Coins"

	local Points = Instance.new("IntValue", nonleaderstats)
	Points.Name = "Points"

	local PromoPoints = Instance.new("IntValue", nonleaderstats)
	PromoPoints.Name = "PromoPoints"

	local multi = Instance.new("IntValue", nonleaderstats)
	multi.Name = "Multiplier"
	
	local QuickLoad=Instance.new("IntValue",nonleaderstats)
	QuickLoad.Name="quickload"


	local data = myDataStore:GetAsync("Player_"..player.UserId)
	if data then 
		print("Player data loaded successfully!")
		Coins.Value = data.Coins or 0
		Points.Value = data.Points or 0
		PromoPoints.Value = data.PromoPoints or 0
		QuickLoad.Value=data.QuickLoad or 0
	else
		print("No player data found for "..player.Name)
	end
end

local function CreateTable(player)
	local PlayerData = {}
	for _, value in ipairs(player.nonleaderstats:GetChildren()) do
		PlayerData[value.Name] = value.Value
	end
	return PlayerData
end

local function OnPlayerRemoving(player)
	local success, errormessage = pcall(function()
		myDataStore:SetAsync("Player_"..player.UserId, CreateTable(player))
	end)

	if success then
		print("Player data was successfully saved for "..player.Name)
	else
		print("Error saving data for "..player.Name..": "..errormessage)
	end
end

Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)

game:BindToClose(function()
	for _, player in ipairs(Players:GetPlayers()) do
		OnPlayerRemoving(player)
	end
end)
4 Likes

did you change the name of “myDataStore”?

1 Like

Nope, just added the QuickLoad variable

1 Like

there could’ve been an error in loading data and/or saving data

check if there are any prints (not error or warning, but prints) that says “No player data found for” or “Error saving data for”

It says success, and it’s not firing the error print.

I have been caught up with the same problem over a year ago where ROBLOX removed the capability of changing values of data through a client to serversided script within ServerScriptService. In whatever that has been changing your data, make sure it is a Server Script in Game.Workspace.

If this helps, mark it as a solution so that future developers who revisit this post will know about the cause.

1 Like

It worked for every value exept for QuickLoad. There isn’t anything that QuickLoad doesn’t have that the other values do.

QuickLoad.Value=data.QuickLoad or 0

In this line here, you have placed QuickLoad as capitals for the start of both words.

QuickLoad.Name="quickload"

However, if you look at this line, the name is “quickload” and not “QuickLoad”.

2 Likes

That still doesn’t fix my problem. Would it have to be something to do with the way I change the data?

Change this to:

local data = myDataStore:GetAsync("Player_"..player.UserId)
	if data then 
		
		Coins.Value = data.Coins or 0
		Points.Value = data.Points or 0
		PromoPoints.Value = data.PromoPoints or 0
		QuickLoad.Value = data.QuickLoad or 0
print("Player data loaded successfully!")
	else

This will only allow the printing part to happen if these values have all been added/loaded.