Datastore does not save and there is no errors

so i defined my leaderstats inside a folder that was called “leaderstats”. that folder was inside another folder called, “PlayerData”, and that folder was inside a serverscript in serverscriptservice.

i then made a different serverscript inside serverscriptservice and i asked for help. The dude fixed it, but then it broke and whenever i would add any values to the leaderstats it wouldn’t save. This is the script:

local DSS = game:GetService(“DataStoreService”)
local DataStore = DSS:GetDataStore(“LeaderstatsDataStoreTest1”)
local Players = game:GetService(“Players”)

game.Players.PlayerAdded:Connect(function(player)
local Coins = player:WaitForChild(“leaderstats”).Coins
local Gems = player:WaitForChild(“leaderstats”).Gems

local success, data = pcall(DataStore.GetAsync, DataStore, player.UserId)

if success then
	Gems.Value = data.Gems
	Coins.Value = data.Coins

	print("Data loaded")
else
	print("Error: ", data)
end

end)

game.Players.PlayerRemoving:Connect(function(player)
local data = {
Gems = player.leaderstats.Gems.Value,
Coins = player.leaderstats.Coins.Value
}

local success, error = pcall(DataStore.SetAsync, DataStore, player.UserId, data)

if success then
	print("Data Successfully Saved!")
else
	print("Error: ", error)
end

end)

This is not how the Pcall function is done.

do you know how to fix it?
(have to type something here to send)

local DataStore = game:GetService("DataStoreService"):GetDataStore("MyData")
local data
local success, response = pcall(function()
    data = DataStore:GetAsync("key")
end)

This didnt really help i still dont know how to fix it

There’s nothing wrong with that pcall. The tutorial you linked in fact gives an example just like it:

local DataStore = game:GetService("DataStoreService"):GetDataStore("MyData")
local success, response = pcall(
    DataStore.GetAsync, --1
    DataStore, --2
    "key" --3
)

do you have api services enabled?

Yes of course i do. I enabled it a long time ago.

This is a full working demo. There are two parts in my Workspace, named GemsPart and CoinsPart and when the player steps on the parts, it increases their totals.

Put the following in ServerScriptService:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("LeaderstatsDataStoreTest")

game.Players.PlayerAdded:Connect(function(player: Player)	
	-- Create the leaderstats
	local leaderStats = Instance.new("Folder")
	leaderStats.Name = "leaderstats"
	leaderStats.Parent = player
	
	-- Create the Coins value
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = 0
	coins.Parent = leaderStats
	
	-- Create the Gems value
	local gems = Instance.new("IntValue")
	gems.Name = "Gems"
	gems.Value = 0
	gems.Parent = leaderStats
	
	-- Update this player's stats from DataStore
	local success, data = pcall(DataStore.GetAsync, DataStore, player.UserId)
	
	if success then
		coins.Value = data.Coins
		gems.Value = data.Gems
	end	
end)

game.Players.PlayerRemoving:Connect(function(player)
	local data = {
		Gems = player.leaderstats.Gems.Value,
		Coins = player.leaderstats.Coins.Value
	}

	local success, error = pcall(DataStore.SetAsync, DataStore, player.UserId, data)
end)

game.Workspace.GemsPart.Touched:Connect(function(other: BasePart)
	local player = game.Players:GetPlayerFromCharacter(other.Parent)
	
	if player then		
		player.leaderstats.Gems.Value += 1
	end
end)

game.Workspace.CoinsPart.Touched:Connect(function(other: BasePart)
	local player = game.Players:GetPlayerFromCharacter(other.Parent)

	if player then		
		player.leaderstats.Coins.Value += 1
	end
end)

ServerScriptService.Script:13: attempt to index number with ‘Value’

whenever i change the value it wont save when i rejoin

I’m not sure what to tell you at this point. The above code works just fine for me. You can additionally add a call to BindToClose() but I don’t think that’s the core issue here.