So i am currently experimenting with tables so tried making a very simple crafting system.
Unfortunately the script gives player every tool by crafting only one of them even though i set everything right(i think).
Here is my script
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local open_button = script.Parent.Open
local close_button = script.Parent.BG.Close
open_button.MouseButton1Click:Connect(function()
script.Parent.BG.Visible = true
end)
close_button.MouseButton1Click:Connect(function()
script.Parent.BG.Visible = false
end)
local craft_frame = script.Parent.BG.CraftFrame
local requirements_frame = craft_frame.Parent.RequirementsFrame
local recipes_frame = craft_frame.Parent.RecipesFrame
local craft_button = craft_frame.CraftButton
local Backpack = player.Backpack
local Tools = {
Axe = {"Log", "Fiber", ReplicatedStorage.Tools.Axe};
DiamondSword = {"Diamond", "Blackstone", ReplicatedStorage.Tools["Diamond Sword"]}
}
for _, button in pairs(recipes_frame:GetChildren()) do
if button:IsA("TextButton") then
button.MouseButton1Click:Connect(function()
if button.Name == "Axe" then
requirements_frame.Requirement1.Text = Tools.Axe[1]
requirements_frame.Requirement2.Text = Tools.Axe[2]
craft_button.MouseButton1Click:Connect(function()
if Backpack:FindFirstChild(Tools.Axe[1]) and Backpack:FindFirstChild(Tools.Axe[2]) then
Backpack:FindFirstChild(Tools.Axe[1]):Destroy()
Backpack:FindFirstChild(Tools.Axe[2]):Destroy()
Tools.Axe[3].Parent = Backpack
end
end)
elseif button.Name == "Diamond Sword" then
requirements_frame.Requirement1.Text = Tools.DiamondSword[1]
requirements_frame.Requirement2.Text = Tools.DiamondSword[2]
craft_button.MouseButton1Click:Connect(function()
if Backpack:FindFirstChild(Tools.DiamondSword[1]) and Backpack:FindFirstChild(Tools.DiamondSword[2]) then
Backpack:FindFirstChild(Tools.DiamondSword[1]):Destroy()
Backpack:FindFirstChild(Tools.DiamondSword[2]):Destroy()
Tools.DiamondSword[3].Parent = Backpack
end
end)
end
end)
end
end