I would create some sort of module you can access from both the client and the server that allows you to quickly and easily access inventory contents, e.g.
local InventoryManager = require(ReplicatedStorage.Shared.InventoryManager)
-- on the server
local playerInventory = InventoryManager:GetPlayerInventory(player)
if not playerInventory[1] then
InventoryManager:SetPlayerInventory(player, { InventoryManager.newTool("Knife") })
end
-- on the client
local playerInventory = InventoryManager:GetLocalPlayerInventory()
local slotOne = playerInventory[1]
thats because the inventory variable is where it is gotten, so it should be like this:
game.Players.PlayerAdded:Connect(function(plr)
_G[plr.Name.."inventory"] = invds:GetAsync(plr.UserId) or {
["Knife1"] = {
["Amount"] = 10;
};
["Knife2"] = {
["Amount"] = 10;
};
["Knife3"] = {
["Amount"] = 10;
};
["Knife4"] = {
["Amount"] = 10;
};
["Knife5"] = {
["Amount"] = 10;
};
};
--btw I'm moving the saving part
end)
game.Players.PlayerRemoving:Connect(function(plr)
invds:SetAsync(plr.UserId, _G[plr.Name.."inventory"])
end)
--because studio shuts the game down and doesn't fire the PlayerRemoving function
game:BindToClose(function()
for i,plr in pairs(game.Players:GetPlayers() do
invds:SetAsync(plr.UserId, _G[plr.Name.."inventory"])
end
end)
it didn’t save on studio because of it not firing the PlayerRemoving event so I added BindToClose. Also, another reason it didn’t save was because you never got the data for the _G variable and left it as inventory variable meaning it never got the data. It should work now.
the name of the datastore is Inventory and the scope is the id of the game I’m pretty sure. I don’t use datastore editor much.
edit: scope is something you don’t need to enter. you only need the name of the data store. Also, the key is the id of the player.