Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Services
- local ds = game:GetService("DataStoreService"):GetDataStore("TutorialData") -- Replace TutorialData with your Datstore Name.
- --// Functions
- game.Players.PlayerAdded:Connect(function(plr) -- On player enter
- local Prefix = plr.UserId -- Quick access to the Users ID.
- local leaderstats = Instance.new("Folder", plr) -- Creates a new folder for the Cash to go in. the 2nd parameter is for the Parent.
- leaderstats.Name = "leaderstats" -- Names it
- local Cash = Instance.new("IntValue", leaderstats) -- Creates a IntValue for Cash.
- Cash.Name = "Cash" -- Names it
- local CashData = nil -- To grab the data of the value we'll store the value into this variable.
- pcall(function()
- CashData = ds:GetAsync(Prefix) -- Sets the Variable to the Value saved or makes it nil for a new player.
- end)
- if CashData ~= nil then -- If the user does have data then we can load it into the Cash.
- Cash.Value = CashData
- else
- Cash.Value = 0 -- Else if CashData == nil then creates a new amount for the player. aka as the Start value
- end
- end)
- game.Players.PlayerRemoving:Connect(function(plr) -- On player leave
- local Prefix = plr.UserId -- Quick access to the Users ID.
- local Cash = plr.leaderstats.Cash -- Locates the Players cash.
- pcall(function()
- ds:SetAsync(Prefix, Cash.Value) -- Saves it.
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment