So I've been trying to make a tree chopping down system that only runs when the player equips a tool. Here's what the script looks like so far. (im very very new to scripting)
local part = script.Parent local detector = script.Parent.ClickDetector local hits = 0 local hitsn = math.random(2, 5) local leaves = part.Parent.Leaves local branch = Instance.new("Part") local playerName = game.Players.LocalPlayer.Name local axe = game.Players.LocalPlayer.Backpack.Axe detector.MouseClick:Connect(function(player) if axe.Parent == playerName then if hits == hitsn then print("tree has been chopped!") hits = 0 part.Anchored = false leaves.Anchored = false wait(2) part:Destroy() leaves:Destroy() branch.Anchored = false branch.Parent = workspace.Items else print("not yet!") hits = hits + 1 end end end)
i think it could be an issue with line 8, and how i assigned the axe but i really don't know. just so you know, im not using the default roblox inventory, im using an inventory system that i found on the toolbox that i customised a bit.
This script detects when the player equips the tool in his hand, you can try to use it to do what you want.
local player = game.Players.LocalPlayer local Tool = player.Backpack:FindFirstChild("NameTool") or player.Character:FindFirstChild("NameTool") Tool.Equipped:Connect(function(mouse) print("the tool is equipped") --This function will only be activated when the player equips the tool end)