Datastore not saving

For some reason none of my datastores have been saving on roblox.

My datastore code is not saving but it’s not saying any errors.

local dataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")
local mainStore = dataStoreService:GetDataStore("MainDataStore")

players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Subscribers = Instance.new("IntValue")
	Subscribers.Name = "Subscribers"
	Subscribers.Parent = leaderstats
	
	local success,data = pcall(function()
		return mainStore:GetAsync(player.UserId)
	end)
	if success then
		Subscribers.Value = data
	else
		print("Failed to load data")
	end
end)

players.PlayerRemoving:Connect(function(player)
	
	local leaderstats = player:WaitForChild("leaderstats")
	local Subscribers = leaderstats:WaitForChild("Subscribers")
	
	local success,err = pcall(function()
		return mainStore:SetAsync(player.UserId, Subscribers.Value)
	end)
	if not success then
		print(err)
	end
end)

API is already turned on. I don’t know what else to do.

1 Like

I can see why it doesn’t get written down. You load data when a player joins the game, but you don’t save data when they leave the game. So if there is no data to load from a previous session, it won’t do it.

And make sure, API Services is turned on

I can help you with create good datastore, or i can send you ready profileservice datastore

1 Like

Nah, sorry. I didnt see players.PlayerRemoving

1 Like

You say you can help me create a good datastore? How? I’m looking to make 2 values, Subscribers and Money.

I know how to make the leaderstats as I have already make a tutorial lol Leaderstats Tutorial For Noobs

I will try to find my ds system and send it to you. If you only want to store two values, the datastore does not need to be advanced. And just in case, I can send you profliservice. I think 5 minutes max and I’ll have it.

1 Like

Alright thank you very much for the help.

No problem. Btw, I can’t find good game file with ds. Do you think you’d find your place in profileservice? I could explain it to you in 5 minutes max

As long as it’s easy i’m fine with it…

Believe me, very simple. I’m already sending you the game file from profileservice and I’ll start explaining it step by step.

Do you want it as leaderstats?

Actually see, you named folder leaderstats. So here’s file with it:

Yes, and I want the value names to be “Subscribers” and “Money”

ok let me do this[d;a[afsefsdfs

ok asdjkasd asdk mxc m xcakmxc. m.,asrfmnq;a;lgd as,l;gafgas ga

Idk how to do this this is to much

I just needed a simple datastore

  1. First. If you want to add your own data, go to ServerScriptService, TS, Services and ProfileService.
    Then go to 9 line of code and enter
Money = 0; --How much u want player have when start gameplay
Subscribers = 0; -- Same as money

Sorry XD. But i idk where i have it