Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Services
- local ds = game:GetService("DataStoreService"):GetDataStore("TutorialDataMultipleStats")
- --// Functions
- game.Players.PlayerAdded:Connect(function(plr)
- local Prefix = plr.UserId
- local leaderstats = Instance.new("Folder", plr)
- leaderstats.Name = "leaderstats"
- local Cash = Instance.new("IntValue", leaderstats)
- Cash.Name = "Cash"
- local Gems = Instance.new("IntValue", leaderstats)
- Gems.Name = "Gems"
- local Data = nil -- This will return Nill if a table wasn't found within the Saved Data.
- pcall(function()
- Data = ds:GetAsync(Prefix) -- grabs the saved table and inserts them into the Variable Data
- end)
- if Data ~= nil then -- If there IS data available then
- for i,v in pairs(leaderstats:GetChildren()) do -- loops and loads data
- v.Value = Data[v.Name]
- end
- else -- else no data available then we create start values
- Cash.Value = 200
- Gems.Value = 0
- end
- end)
- game.Players.PlayerRemoving:Connect(function(plr)
- local Prefix = plr.UserId
- local leaderstats = plr.leaderstats -- Finds the Folder
- pcall(function()
- if leaderstats then
- local SaveData = {} -- This table will contain our desired stats to save
- -- Order would look like:
- -- ["Cash"] = 275
- -- ["Gems"] = 100
- for i,v in pairs(leaderstats:GetChildren()) do -- Again loops and finds / saves the data within a table
- SaveData[v.Name] = v.Value
- end
- ds:SetAsync(Prefix, SaveData) -- Saves the data in the SaveData
- end
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment