Data Store not saving the Robux Earned Value or the Robux Donated Value

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

  2. What is the issue? The data store is not saving

  3. What solutions have you tried so far? I tried to look over my code and find that the problem but i still don’t know what the problem is

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- Data Store

local DataStoreService = game:GetService("DataStoreService")

local RobuxDataStore = DataStoreService:GetDataStore("RobuxDataStore")

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	
	local Robux_Donated = Instance.new("IntValue")
	Robux_Donated.Name = "R$ Donated"
	Robux_Donated.Value = 0
	Robux_Donated.Parent = leaderstats
	local Robux_Earned = Instance.new("IntValue")
	Robux_Earned.Name = "R$ Earned"
	Robux_Earned.Value =  0
	Robux_Earned.Parent = leaderstats
	
	local Data
	local Sucess, errormessage = pcall(function()
		Data = RobuxDataStore:GetAsync(Player.Userid.."-R$")
	end)
	if Sucess then
		Robux_Donated.Value = Data
		Robux_Donated.Value = Data
	else
		if not Sucess then
			warn(errormessage)
			print("For some reason the last time you played your data has not saved please look and see if the servers are down if the servers are not down tell us in group and we will look into it and restore your lost data")
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	
	
	local Sucess, errormessage = pcall(function()
		RobuxDataStore:SetAsync(Player.UserId.."-R$", Player.leaderstats.Robux_Earned.Value,Player.leaderstats.Robux_Donated.Value)
	end)
	
	if Sucess then
		print("Data Sucessfully Loaded!!")
	else
		if not Sucess then
			print("There was an error when saving data")
			warn(errormessage)
		end
	end
end)

I got a problem where my data store is not having does anyone know the problem thanks for your help.

Let me know if this works for you! Remember to turn on Studio access to api services.

Pin this as a resolution if it worked!

local DataStoreService = game:GetService("DataStoreService")

local RobuxDataStore = DataStoreService:GetDataStore("RobuxDataStore")

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

	local Robux_Donated = Instance.new("IntValue")
	Robux_Donated.Name = "R$ Donated"
	Robux_Donated.Value = 0
	Robux_Donated.Parent = leaderstats
	local Robux_Earned = Instance.new("IntValue")
	Robux_Earned.Name = "R$ Earned"
	Robux_Earned.Value =  0
	Robux_Earned.Parent = leaderstats

	local ID = "Player_"..Player.UserId
	local savedData = nil
	local Sucess, errormessage = pcall(function()
		savedData = RobuxDataStore:GetAsync(ID)
	end)
	if Sucess then
		if savedData ~= nil then
			Robux_Donated.Value = savedData.Donated
			Robux_Earned.Value = savedData.Earned
		else
			print("No data")
		end
	else
		warn(errormessage)
		print("For some reason the last time you played your data has not saved please look and see if the servers are down if the servers are not down tell us in group and we will look into it and restore your lost data")
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	
	local data = {
		["Donated"] = Player.leaderstats["R$ Donated"].Value,
		["Earned"] = Player.leaderstats["R$ Earned"].Value
	}


	local ID = "Player_"..Player.UserId
	
	local success, errormessage = pcall(function()
		RobuxDataStore:SetAsync(ID,data)
	end)
	
	if success then
		print("Saved")
	else
		print("There was an error saving")
		warn(errormessage)
	end
end)
Data = RobuxDataStore:GetAsync(Player.Userid.."-R$")

Should be UserId.

I mean it worked for him and I don’t think he has DataStoreEditor so it’s probably something he finds out himself.

image

That was his issue.

I know that it doesn’t work, but he solved it probably. This is a solved case.

I was providing an explanation for why your solution worked.

1 Like