Help with datastore of leaderstats

Hello, I wanted to make 4 Values in the leaderstats. But the fourth is not working. I dont know why. I ask for help if anyone know how to fix this thanks.
The ERROR IS HERE:

  11:49:16.944  click is not a valid member of Folder "Players.do0gdemon.leaderstats"  -  Server - MoneyGiver:2

HERE IS THE CODE IS USE!
BTW THIS CODE WORKED BEFORE ADDING THE FOURTH VALUE!

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SaveData")


local function SavePlayerData(player)

	local success, errormsg = pcall(function()

		local SaveData = {}

		for i, stats in pairs(player.leaderstats:GetChildren()) do

			SaveData[stats.Name] = stats.Value
		end	
		SaveDataStore:SetAsync(player.UserId, SaveData)
	end)

	if not success then 
		return errormsg
	end			
end	


Players.PlayerAdded:Connect(function(player)

	local Stats = Instance.new("Folder")
	Stats.Name = "leaderstats"
	Stats.Parent = player

	local cps = Instance.new("IntValue")
	cps.Name = "cps"
	cps.Value = 0
	cps.Parent = Stats
	

	local ShopData = Instance.new("IntValue")
	ShopData.Name = "ShopData"
	ShopData.Value = 0
	ShopData.Parent = Stats


	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Value = 0
	Cash.Parent = Stats
	
	local click = Instance.new("IntValue") -- I ADDED THIS INTVALUE AND IT DOESN WORK
	click.Name = "Click"
	click.Value = 0
	click.Parent = Stats



	local Data = SaveDataStore:GetAsync(player.UserId)

	if Data then

		for i, stats in pairs(Stats:GetChildren()) do

			stats.Value = Data[stats.Name]
		end		

	else		
		print(player.Name .. " has no data.")			
	end




end)


Players.PlayerRemoving:Connect(function(player)

	local errormsg = SavePlayerData(player)

	if errormsg then	
		warn(errormsg)		
	end	
end)

game:BindToClose(function()
	for i, player in pairs(Players:GetPlayers()) do	

		local errormsg = SavePlayerData(player)
		if errormsg then
			warn(errormsg)
		end			
	end
	wait(2)	
end)

What type of script is this and where is it located? Please can you provide more information!

Its in serversscriptservice and its normal script

Have you allowed studio to api service?

Ye it works with the others, Cash, Shopdata and scp, BUT NOT IN THE CLICK!

Ok I copied your code and it worked fine for me? Very strange I will look into it in greater detail later in about 1 and a half hours! Sorry for making you wait!

1 Like

One thing are there any scripts trying to add to the values?

Yes, I do, Was testing the value with this script.

game.ReplicatedStorage.GiveMoney.OnServerEvent:Connect(function(player)
player.leaderstats.click.Value = player.leaderstats.click.Value + 1


	
end)

if you disable that script does it work?

Ye it dosnt print any errors but how I add value to “click” if it doesn¨t work?

ok i will write a quick code one sec

1 Like

You mispelled click. You made the C lowercase.

This is the adding code that I think may work:
Code:

local player = game.Players.LocalPlayer

game.ReplicatedStorage.GiveMoney.OnServerEvent:Connect(function()

player.leaderstats.Click.Value = player.leaderstats.Click.Value + 1

end)

1 Like

lol it worked i changed it thanks.
Sometimes the littlest miss-spells are crashing evrythng. Thanks!

Make sure to mark that post as solution.

1 Like

That code is incorrect and wont work