i have this script
local currencyName = "Point"
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
currency.Value = 0
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
currency.Value = savedData
print("Data loaded")
else
-- New player
currency.Value = 0
print("New player to the game")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = currencyName.."-"..player.UserId
DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
print("Saved")
end)
game:BindToClose(function()
-- When game is ready to shutdown
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("This game is shutting down")
end
end
wait(3)
end)
shop script
local price = script.Parent.Parent.Price
local tools = game:GetService("ReplicatedStorage"):WaitForChild("Tools")
local tool = tools:FindFirstChild(script.Parent.Parent.ItemName.Value)
local player = script.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats:WaitForChild("Point") then
if player.leaderstats.Point.Value >= price.Value then
player.leaderstats.Point.Value = player.leaderstats.Point.Value - price.Value
local clone = tool:Clone()
clone.Parent = player.Backpack
local clone2 = tool:Clone()
clone2.Parent = player.StarterGear
end
end
end)
Actually, it works. When you play, if you buy the Points from the gamepass, the points is still be saved. But when you use that points to buy things in shop, the script doesn't save the points which have been decrease. Can anyone solve the problem? Thanks you guys a lot

2 comments
You don't give the script of the shop? How are we supposed to find a solution then? However, the problem may be that you're changing the value of points on the client, so the server doesn't recognize it. Are you using RemoteEvents to decrease the points?
ok