I have a shop script that uses a crafting system, but in a way my shop is unfair. Let me explain:
EX: Jimmy wants to try to buy a sword, he has 3 mushrooms but not 2 cows, when he presses the button, all the required amount of Jimmy's mushrooms are gone and the transaction is not made.
local items = script.Parent.Frame:GetChildren()
for i = 1, #items do
function buy()
local item1 = items[i]:FindFirstChild("Item1")
local item2 = items[i]:FindFirstChild("Item2")
local item3 = items[i]:FindFirstChild("Item3")
local item4 = items[i]:FindFirstChild("Item4")
local item5 = items[i]:FindFirstChild("Item5")
local Cash = script.Parent.Parent.Parent.Parent.leaderstats:FindFirstChild("Gold")
if item1 then
if script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item1.Value).Value > items [i].item1Price.Value then
script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item1.Value).Value = script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item1.Value).Value - items [i].item1Price.Value
else return
end
end
if item2 then
if script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item2.Value).Value > items [i].item2Price.Value then
script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item2.Value).Value = script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item2.Value).Value - items [i].item2Price.Value
else return
end
end
if item3 then
if script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item3.Value).Value > items [i].item3Price.Value then
script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item3.Value).Value = script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item3.Value).Value - items [i].item3Price.Value
else return
end
end
if item4 then
if script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item4.Value).Value > items [i].item4Price.Value then
script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item4.Value).Value = script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item4.Value).Value - items [i].item4Price.Value
else return
end
end
if item5 then
if script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item5.Value).Value > items [i].item5Price.Value then
script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item5.Value).Value = script.Parent.Parent.Parent.Parent.Materials:FindFirstChild(item5.Value).Value - items [i].item5Price.Value
else return
end
end
if Cash.Value >= items[i].Cost.Value then
Cash.Value = Cash.Value - items[i].Cost.Value
local tool1 = game.ReplicatedStorage:FindFirstChild (script.Parent.Folder.Value):FindFirstChild(items[i].ItemName.Value):Clone()
local tool2 = game.ReplicatedStorage:FindFirstChild (script.Parent.Folder.Value):FindFirstChild(items[i].ItemName.Value):Clone()
tool1.Parent = script.Parent.Parent.Parent.Parent.Backpack
tool2.Parent = script.Parent.Parent.Parent.Parent.StarterGear
print("Purchase successful.")
end
items[i].BuyButton.MouseButton1Click:connect(buy)
end
end
no errors appear in the output or script analysis

2 comments
but not all weapons have 5 items for crafting.
Then make it suitable? Your issue isn't that not all weapons need 5, it's that when you only have some it removes what you have and escapes. My solution fixes that issue.