Hi,
Can someone please help with why my simple exmple DataStore2 script below is not saving data? when I end the game and go in the coins reset to 0
local DataStore2 = require(game.ServerScriptService:WaitForChild(“MainModule”))
DataStore2.Combine(“MasterKey”, “coins”, “gems”)
game.Players.PlayerAdded:Connect(function(plr)
local dataCoins = DataStore2("coins", plr)
local dataGems = DataStore2("gems", plr)
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats"
local coins = Instance.new("IntValue", folder)
local gems = Instance.new("IntValue", folder)
coins.Name = "coins"
gems.Name = "gems"
-- Load Data
if dataCoins:Get() ~= nil then
coins.Value = dataCoins:Get()
else
coins.Value = 0
end
if dataGems:Get() ~= nil then
gems.Value = dataGems:Get()
else
gems.Value = 0
end
-- Save data
coins.Changed:Connect(function()
dataCoins:Set(coins.Value)
end)
gems.Changed:Connect(function()
dataGems:Set(gems.Value)
end)
end)
game.Workspace:WaitForChild(“Part”).ClickDetector.MouseClick:Connect(function(plr)
print("clicked")
plr.leaderstats.coins.Value = plr.leaderstats.coins.Value + 1
end)