Hey all, I’ve been learning ProfileStore recently, as it seems like a good jumping off point for learning about Datastores. I’ve got the main profile saving system set up according to this YouTube tutorial.
I have two basic pieces of data: Cash, and the player’s inventory. The AddCash() function seems to work just fine, but it’s adding tools to the player’s inventory that just doesn’t work…
function Shared.AddCash(player: Player, amount: number)
local data = Shared.GetData(player) -- GetData returns Profiles[profile].Data
if not data then return end
print("Data exists for "..player.Name)
local cash = data.Cash
data.Cash += amount
print(`player has {cash} cash`)
print(Shared.GetData(player))
end -- this works
I split the UpdateInventory() function into two parts, one that adds the item to the player’s profile Inventory, and one that adds the item to the player’s backpack:
function Shared.UpdateInventory(player: Player, item: string)
local data = Shared.GetData(player)
if not data then
warn("Data cannot be found for "..player.Name.." !")
return
end
print("data exists")
local inventory = data.Inventory
table.insert(inventory, item)
print("Inserted into inventory")
print(Shared.GetData(player))
end
function Shared.AddToBackpack(player: Player, item: string)
local data = Shared.GetData(player)
if not data then
warn("Data cannot be found for "..player.Name.." !")
return
end
print("data exists")
local asset = ReplicatedStorage:WaitForChild("Assets"):FindFirstChild(item)
if not asset then
asset = ReplicatedStorage:WaitForChild("ModelAssets"):FindFirstChild(item)
end
print("Asset found.")
if asset then
asset.Parent = player.Backpack
end
print(Shared.GetData(player))
end
No matter which value I pass through this function, it always returns nil, and it’s driving me insane.
clickDetector.MouseClick:Connect(function(player)
if not player then return end
local item = script.Parent.Parent.Parent
PlayerData.UpdateInventory(item.Name) -- somehow always ends up passing nil.
print("added "..item.Name.." to inventory!")
PlayerData.AddToBackpack(item.Name) -- same issue here.
print("added "..item.Name.." to backpack!")
item:Destroy()
end)
^^^
Example where I click on a tool and it adds the tool to the player’s inventory (in theory)

I really don’t know what I’m getting wrong here. If someone is able to help me figure out what I need to do to make a functioning inventory system here, please let me know! I’m new to DataStores in general and would really appreciate some assistance.