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)
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.
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.
-- 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.
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
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.
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