How do I save a arbitrary value in ProfileStore? (INVENTORY SYSTEM)

I’m making a inventory system using ProfileStore, and the tools inside my game have custom variables such as Favorited and Weight. The value Weight is a fixed value, so it doesn’t change.

The problem though is that I can’t figure out how to save a value that changes. Players can change if they want an item Favorited. So whenever a player requests to favorite an item, it needs to be updated to the profile of the player.

I made a function called UpdateItem, and whenever a player requests to favorite an item, the function finds a identical item and updates it’s value.

The function works, but the problem is how whenever there are multiple identical items, such as potatoes with the same class and weight, the function finds the first identical item and updates that item.

Goal: Update the exact item the player requests to interact with(instead of the first identical item).

function DataManager:UpdateItem(player, item)
	local profile = DataManager.Profiles[player]
	if not profile then return end

	local itemData = itemModule:getItemData(item)
	 -- itemData = {Class = <ClassName>, Weight = <Weight>, Favorited = <Favorited>}
	for i, invItem in profile.Data.Inventory do
		if invItem.Class == itemData.Class and (invItem.Weight == itemData.Weight or (invItem.Weight == nil and itemData.Weight == nil)) then
			profile.Data.Inventory[i].Favorited = itemData.Favorited
			break
		end
	end
end

add a unique id to each item (also change it to only compare ids instead of all the other values)

you can use HttpService:GenerateGUID(false)

so all of the Id’s will be different? including other items that aren’t picked up by the same player?

names should be easier and enough for unique identification

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.