basically i am clicking a part and when i click it i want to gain 1 value of cheese leaderboard stat
this is my datastore script
local dataStoreService = game:GetService("DataStoreService")
local myDataStore = dataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Cheese = Instance.new("IntValue")
Cheese.Name = "Cheese"
Cheese.Parent = leaderstats
local playerUserId = "Player_"..player.UserId
-- loading data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
-- set data = current cheese
Cheese.Value = data
end
end)
-- saving cheese when player leaves
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = player.leaderstats.Cheese.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("cheese saved")
else
print("error while saving cheese")
warn(errormessage)
end
end)```
this is my script for the part to click. the error message is "Cheese is not a valid member of Folder "Players.sadicity.leaderstats" but it definitely should be and i check and its there i dont know whats wrong
```lua
local miningclicker = script.Parent
local detector = miningclicker.ClickDetector
detector.MouseClick:Connect(function(player)
local cheeses = player.leaderstats.Cheese.Value
player.leaderstats.Cheese = cheeses + 1
end)```