Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local currencyName = "Money"
- local DataStore = game:GetService("DataStoreService"):GetDataStore("LLDSSDS")
- 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 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 = 100
- 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)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement