Destroy shop entry if player already has the item

Ok so I already made a thread on this but I had a better idea. Basically the player’s inventory is stored under the localplayer, like this
image
and the way the shop has it is when the shop window is open, it has the items displayed in the PlayerGui and they are stored in this
image
how would I have a shop icon destroyed if it exists in the player’s inventory?

Like on the last post that I did, you can make the localscript do a scan of the players inventory when they make a purchase.

I don’t know any specifics about your scripts or similar, however:
When you make the shop GUI visible, scan through all frames/items and destroy or hide or (best option) grey out/“disable” any items which the player already owns.

(code is illustrative and will not fit in your project, in all likelyhood)

local OwnedPacks -- folder which contains ValueObjects
local Inv -- grid frame which contains Frames

function OpenShop()
	-- update item visibility
	for _,frame in ipairs(Inv:GetChildren()) do
		-- if item is owned
		if OwnedPacks:FindFirstChild(frame.Name) then
			DisableItem(frame)
		else
			-- feel free to remove this if it is impossible to lose items
			EnableItem(frame)
		end
	end
	
	-- another way is to loop through all OwnedPacks and destroy the corresponding item in Inv if it exists
	
	-- now show the inventory (your code here)
end

function DisableItem(frame)
	-- grey out a frame
	-- or just destroy it
	frame:Destroy()
end

function EnableItem(frame)
	-- un-grey a frame, in case you did not destroy the frames
end

Also a little tap on the shoulder: if you store items as instances inside the Player, then exploiters can see what items other players have.
If you don’t like this, then move the items to ServerStorage or a table in a modulescript, or give all players the ability to peer into others’ inventories so that the exploiters aren’t any better.

3 Likes