Help Script, bad functions?

I am doing a crafting system but when crafting the object the tool does not work even you can not throw the tool,
I’ve been checking other people’s scripts to see what code they use and if they work,
But for some reason it does not work in my code, will it be that in local script it does not exist? I leave the code

local CraftPart1 = "Log"   ------------------------------ Craft Part 1
local CraftPart2 = "Stick" ------------------------------ Craft Part 2
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Backpack
local Destroyed = false
script.Parent.MouseButton1Click:Connect(function()
if Player:FindFirstChild(CraftPart2) then ------------------------------ Craft Part 2
Player.Stick:Destroy()
Destroyed = true
if Player:FindFirstChild(CraftPart1) then -------------------------- Craft Part 1
Player.Log:Destroy()
Destroyed = false
local item = game.ReplicatedStorage.Crafting.PickAxeBroken:Clone() --------------------Crafted Item
item.Parent = Player
else
if Destroyed == true then
local giveback = game.ReplicatedStorage.Crafting.Log:Clone()
giveback.Parent = Player
end
end
end
end)

This code was my script it works but when duplicating the tool in the player's inventory it does not work (the scripts and the tool),
this is the part that i think fails
"" (local item = game.ReplicatedStorage.Crafting.PickAxeBroken: Clone () -------------------- Crafted Item
item.Parent = Player) "".

This is another code from a person that I found in the toolbox. It does almost the same function as my script, but with the difference that the tool works, including the scripts.

function hi(x)
local y = x.Backpack
local z = game.Lighting[“Tool Name”] --Change “Tool Name” to the name of your tool.
z:Clone().Parent = y
end

script.Parent.ClickDetector.MouseClick:connect(hi)

– armyboy1133 Youtube´´´

modify that code so that it works in GUI and serbia when I try to mix that script from the toolbox with mine it stopped working I don’t know because there is some way to solve the unusable tool when duplicating?

this is the modified code that I made by combining the toolbox code and my original code

function hi(x)
local CraftPart1 = "Log"   ------------------------------ Craft Part 1
local CraftPart2 = "Stick" ------------------------------ Craft Part 2

	local y = x.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Backpack
	local z = game.ReplicatedStorage.Crafting["PickAxeBroken"]
	
local Destroyed = false
	
	script.Parent.MouseButton1Click:connect(hi)
	if y:FindFirstChild(CraftPart2) then ------------------------------ Craft Part 2
		y.Stick:Destroy()
		Destroyed = true
		if y:FindFirstChild(CraftPart1) then -------------------------- Craft Part 1
			y.Log:Destroy()
			Destroyed = false
			z:Clone().Parent = y
		else
			if Destroyed == true then
				local giveback = game.ReplicatedStorage.Crafting["Log"]
				giveback:Clone().Parent = y
			end
		end
	end

Please use
3 tick backs when writing code, they are right underneath the esc key!
PS: You used ‘’’ when you should’ve used ```

1 Like