In my current script when you click a certain block of a tree the rest falls down, How can I get it so only when you have a tool with the name "Axe" you are able to harvest the tree? I have been trying a lot of things but nothing works.
wait(2) local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local char = plr.Character local x = script:FindFirstChild("Wood") local GetWood = true function ShowProgress(tree) if tree == 'SmallTree1' then for i = 0,1,.01 do WC.BG.Progress.Size = UDim2.new(i,0,1,0) wait() end elseif tree == 'MediumTree' then for i = 0,1,.005 do WC.BG.Progress.Size = UDim2.new(i,0,1,0) wait() end end end mouse.Button1Down:connect(function() if mouse.Target ~= nil and mouse.Target.Parent.Name == 'SmallTree1' and GetWood == true then local Wood = mouse.Target if (Wood.position - char.UpperTorso.position).magnitude < 10 then GetWood = false WC = plr.PlayerGui.WoodChopper WC.BG.Visible = true ShowProgress('SmallTree1') for i,v in pairs(Wood.Parent.Leaves:GetChildren()) do if v:IsA('Part') then v.Anchored = false end end for i,l in pairs(Wood.Parent.Logs:GetChildren()) do if l:IsA('Part') then l.Anchored = false end end Wood:Destroy() WC.BG.Visible = false GetWood = true end end end)
So, you would need to access the players' backpack, which will be easy since this is a LocalScript
.
wait(2) local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local char = plr.Character local x = script:FindFirstChild("Wood") local GetWood = true function ShowProgress(tree) if tree == 'SmallTree1' then for i = 0,1,.01 do WC.BG.Progress.Size = UDim2.new(i,0,1,0) wait() end elseif tree == 'MediumTree' then for i = 0,1,.005 do WC.BG.Progress.Size = UDim2.new(i,0,1,0) wait() end end end mouse.Button1Down:connect(function() if game.Players.localPlayer.Backpack:FindFirstChild("Axe") if mouse.Target ~= nil and mouse.Target.Parent.Name == 'SmallTree1' and GetWood == true then local Wood = mouse.Target if (Wood.position - char.UpperTorso.position).magnitude < 10 then GetWood = false WC = plr.PlayerGui.WoodChopper WC.BG.Visible = true ShowProgress('SmallTree1') for i,v in pairs(Wood.Parent.Leaves:GetChildren()) do if v:IsA('Part') then v.Anchored = false end end for i,l in pairs(Wood.Parent.Logs:GetChildren()) do if l:IsA('Part') then l.Anchored = false end end Wood:Destroy() WC.BG.Visible = false GetWood = true end end end end)
NOTE: I DID NOT FIX/CHANGE ANYTHING WITH THE SCRIPT OTHER THAN ADD THE TOOL FINDER.