Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I use datastores for a custom inventory?

Asked by 4 years ago

I know how to use datastores, but I cant quite figure out how to make it work with the inventory system? Anyone have any suggestions?

0
Do you have any code you'd like to share? If you understand DataStores, you should've been able to compile at least an attempt at saving the inventory system. BryanFehr 133 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

The code i local Data = game:GetService("DataStoreService"):GetDataStore("Inventory") game.Players.PlayerAdded:Connect(function(plr) local SavedStuff = Data:GetAsync(plr.userId) if SavedStuff == nil then for i,v in pairs(SavedStuff)do if game.ServerStorage.Inventory:FindFirstChild(v)~= nil then local Weapon = game.ServerStorage.Inventory:FindFirstChild(v):Clone() Weapon.Parent = plr:WaitForChild("Backpack") end end end plr.CharacterRemoving:Connect(function() plr.Character.Humanoid:UnequipTools() end) end)

game.Players.PlayerRemoving:Connect(function(plr) local Table = {} for i,v in pairs(plr.Backpack:GetChildren())do table.insert(Table,v.Name) end if Table ~= nil then Data:SetAsync(plr.userId,Table) end end)

Ad

Answer this question