Created
September 12, 2019 16:40
-
-
Save howmanysmall/16f9ccc81867456b2905dfd449a9a633 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Players = game:GetService("Players") | |
-- Load the DataStore stuff | |
local DEFAULT_DATA = { | |
Money = 0; | |
Inventory = { | |
Cat = false; | |
Dog = false; | |
Fish = true; | |
} | |
} | |
local function LoadData(MainStore, InventoryStore) | |
local Leaderstats = Instance.new("Folder") | |
Leaderstats.Name = "leaderstats" | |
Leaderstats.Parent = Player | |
local Money = Instance.new("IntValue") | |
Money.Name = "Money" | |
Money.Parent = Leaderstats | |
local Inventory = Instance.new("Folder") | |
Inventory.Name = "Inventory" | |
Inventory.Parent = Leaderstats | |
MainStore:Load("Money", 0):Then(function(CashValue) | |
Money.Value = CashValue | |
MainStore:StoreOnValueChange("Money", Money) | |
end):Catch(function(...) warn("Failed to load Money!", ...) end) | |
spawn(function() | |
for PetName, DefaultValue in pairs(DEFAULT_DATA.Inventory) do | |
local Stat = Instance_new("BoolValue") | |
Stat.Name = PetName | |
Stat.Parent = Inventory | |
InventoryStore:Load(PetName, DefaultValue):Then(function(PetValue) | |
Stat.Value = PetValue | |
InventoryStore:StoreOnValueChange(PetName, Stat) | |
end):Catch(function(...) warn("Failed to load", PetName .. "!", ...) end) | |
end | |
end) | |
return Leaderstats | |
end | |
local function PlayerAdded(Player) | |
local DataStore = DataStoreManager:GetDataStore(Player) | |
local MainStore = DataStore:GetSubStore("MainStore") | |
local InventoryStore = DataStore:GetSubStore("InventoryStore") | |
local Leaderstats = LoadData(MainStore, InventoryStore) | |
Leaderstats.Parent = Player | |
end | |
Players.PlayerAdded:Connect(PlayerAdded) | |
for _, Player in ipairs(Players:GetPlayers()) do PlayerAdded(Player) end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment