Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local currencyName = "Money"
- local currencyName2 = "Skills"
- local DataStore = game:GetService("DataStoreService"):GetDataStore("UC")
- 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 currency2 = Instance.new("IntValue")
- currency2.Name = currencyName2
- currency2.Parent = folder
- local ID = currencyName.."-"..player.UserId
- local savedata = nil
- pcall(function()
- savedData = DataStore:GetAsync(ID)
- end)
- if savedData ~= nil then
- currency.Value = savedData
- currency2.Value = savedData
- print("Data loaded")
- else
- --New player
- currency.Value = 0 -----^ How much you began with
- currency2.Value = 15
- 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)
- 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 for saving data and adding updates plz rejoin :D --Fnaf united Dev team CrystalFox123YT")
- end
- end
- wait(5)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement