Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DS = game:GetService("DataStoreService"):GetDataStore("Money")
- GoldStartingValue = --Put how much gold you want a player to start with here!
- game.Players.PlayerAdded:Connect(function(plr)
- local ls = Instance.new("Folder")
- ls.Name = "leaderstats"
- ls.Parent = plr
- local VAL = Instance.new("IntValue")
- VAL.Name = "Gold"
- VAL.Parent = ls
- local data
- local succ, err = pcall(function()
- data = DS:GetAsync(plr.UserId)
- end)
- if err then
- warn("Failed to load data for "..plr.Name)
- end
- if not data then
- data = GoldStartingValue
- end
- VAL.Value = data
- end)
- game.Players.PlayerRemoving:Connect(function(plr)
- local data = plr.leaderstats.Gold.Value
- local succ, err = pcall(function()
- DS:SetAsync(plr.UserId,data)
- end)
- if err then
- warn("Data failed to save for "..plr.Name)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment