Why is the code no saving or loading is working right?
Asked by
5 years ago Edited 5 years ago
``local currencyName = "Coins"
local DataStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
game.Players.PlayerAdded:Connect(function(player)
01 | local folder = Instance.new( "Folder" ) |
02 | folder.Name = "leaderstats" |
05 | local currency = Instance.new( "IntValue" ) |
06 | currency.Name = currencyName |
07 | currency.Parent = folder |
09 | local ID = currencyName.. "-" ..player.UserId |
13 | local savedData = DataStore:GetAsync(ID) |
16 | if savedData ~ = nil then |
17 | currency.Value = savedData |
end)
game.Players.PlayerRemoving:Connect(function(player)
1 | local ID = currencyName.. "-" ..player.UserId |
3 | DataStore:SetAsync(ID,player.leaderstats [ currencyName ] .Value) |
end)
game:BindToClose(function()
1 | for i, player in pairs (game.Players:GetPlayers()) do |
5 | player:Kick( "this game is shutting down" ) |
end)