Make gui visible when player has enough materials

For my crafting system I want a craftable (the item being crafted) to be visible when the player has enough materials to craft the item.

The craftable: (a frame)
image

Now, if the player has enough of all of these materials, the frame would be visible. If the player doesn’t have enough of these materials then the frame wouldn’t be visible. As simple as this sounds, I haven’t been able to find success with my methods.

Here is my crafting module:

local benchMod = {
	["Wooden Wall"] = {
		[1] = {"Log", 6};
		[2] = {"Rope", 3};
	};
	
	["Wooden Door"] = {
		[1] = {"Log", 5};
		[2] = {"Rope", 2};
	};
};

return benchMod

Any suggestions on how I should do this?

When the crafting menu is opened, loop through all of the materials in the player’s inventory, then compare it with the crafting requirements of the craftable items. If the player has enough, display it, else, don’t.

When I tried this, it didn’t do anything at all.

Here is what I did:

	-- check for enough mats
	
	for _, craftable in pairs(Main[nameOfTab].Inventory:GetChildren()) do -- list of craftables
		if not craftable.Name == "Template" then
			for i, requirements in pairs(benchModule[craftable.Name]) do -- requirements for crafting the craftable
				for _, item in pairs(Player.Inventory:GetChildren()) do -- player inventory
					local check = 0 -- check counter
					if item.Name == requirements[1] and item.Value == requirements[2] the
						check = check + 1
					end
					if check == #requirements then
						craftable.Visible = true
					else
						craftable.Visible = false
					end
				end
			end	
		end
	end

The check counts by 1 each time the player meets the requirements (has material and has enough material) If the counter hits the length of the dictionary (the craftable in the crafting module), it would make the frame visible.

The reason Is because you put the at: if item.Name == requirements[1] and item.Value == requirements[2] the you need to replace the, the with then

try putting

					if check == #requirements then
						craftable.Visible = true
					else
						craftable.Visible = false
					end

outside the requirements loop

I removed the “n” while typing the reply lol

Oh lol. Why? }}}}}}}}}}}}}}}}}

Idk I like to remove characters when typing things on accident

actually, thats only causing half the problem

How are items in the inventory stored?

Ima make a topic about it soon. }}}}}}

In the player inventory? Well it is a simple folder containing a bunch of numbervalues.

Oh I see.

try this?

	for _, craftable in pairs(Main[nameOfTab].Inventory:GetChildren()) do -- list of craftables
		if not craftable.Name == "Template" then
			for i, requirements in pairs(benchModule[craftable.Name]) do -- requirements for crafting the craftable
				for _, item in pairs(Player.Inventory:GetChildren()) do -- player inventory
					if item.Name == requirements[1] and item.Value >= requirements[2] then
						craftable.Visible = true
					else
						craftable.Visible = false
					end
				end
			end	
		end
	end

Craftable is still visible even without the materials in my inventory.

Maybe use a NumberValue. When the player picks up a certain amount of one material, then the frame would be visible. but make sure for every material, you add a NumberValue.

Thats what I do. The inventory is a folder containing a bunch of numbervalues.

But you need to add them to the script and define a variable for all those NumberValues and use a

if NumberValue..Value >= 5 then -- your number before the then.

Thats what this portion is for.

for _, item in pairs(Player.Inventory:GetChildren()) do -- player inventory
	if item.Name == requirements[1] and item.Value >= requirements[2] then
		craftable.Visible = true
	else
		craftable.Visible = false
	end
end

You need to define the NumberVales in the script or use a,

require()

function that came from another script

Have you figured it out yet? (30 letter thing)