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
I Have This DS From My Old Game Here You Go
BTW DO YOU HAVE API SERVICES ON?
local currencyname = "Gems" local DataStore = game:GetService("DataStoreService"):GetDataStore("DataStoreNameHere") local RS = game:GetService("ReplicatedStorage") 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 local SavedData = nil local ID = currencyname.."-"..player.UserId pcall(function() SavedData = DataStore:GetAsync(ID) end) if SavedData ~= nil then currency.Value = SavedData print("Loaded") else --N00B currency.Value = 0 end end) game.Players.PlayerRemoving:Connect(function(player) local ID = currencyname.."-"..player.UserId DataStore:SetAsync(ID, player.leaderstats[currencyname].Value) end) game.BindToClose:Connect(function() for i, player in pairs(game.Players:GetPlayers()) do if player then player:Kick() end end wait(5) end)