Skip to content

Instantly share code, notes, and snippets.

@howmanysmall
Created September 12, 2019 16:40
Show Gist options
  • Save howmanysmall/16f9ccc81867456b2905dfd449a9a633 to your computer and use it in GitHub Desktop.
Save howmanysmall/16f9ccc81867456b2905dfd449a9a633 to your computer and use it in GitHub Desktop.
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