Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DataStore = game:GetService("DataStoreService") --// Getting DataStore Service
- local Ds1 = DataStore:GetDataStore("[ANY NAME IN HERE]") --// You can name your DataStore Anything :)
- game.Players.PlayerAdded:Connect(function(player) --// Creates a function when the player is added to the game :)
- local Folder = Instance.new("Folder", player) --// Making a folder that will be stored in the player.
- Folder.Name = "leaderstats" --// Do not change this name.
- local Coins = Instance.new("IntValue", Folder) --// A IntValue that is being stored in the leaderstats folder.\
- Coins.Name = "Coins" --// Naming the coins
- Coins.Value = Ds1:GetAsync(player.UserId) or 0 --// Getting the data player data
- Ds1:SetAsync(player.UserId, Coins.Value) --// Setting the player Data
- Coins.Changed:Connect(function()
- print("Saving Data")
- Ds1:SetAsync(player.UserId, Coins.Value) --// When your coins is changed it will save your data
- end)
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- print("Player Has Left")
- Ds1:SetAsync(player.UserId, player.leaderstats.Coins.Value)
- end)
Advertisement
Advertisement