I want to make a script that when a player clicks a certain part with a tool, (In my case a tree with a axe) it will run a animation and makes the "tree" unanchored. I really cant get it to work, I'm new to coding. I have removed a few parts of the script to make it more clear (O its a localscript)
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local char = plr.Character local x = script:FindFirstChild("Wood") local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation) mouse.Button1Down:connect(function() if game.Players.localPlayer.Backpack:FindFirstChild("Axe") and 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 char.Humanoid.WalkSpeed = 0 char.Humanoid.JumpPower = 0 animation:Play() ShowProgress('SmallTree1') animation:Stop() char.Humanoid.WalkSpeed = 16 char.Humanoid.JumpPower = 50
On line 11, when a player takes out a tool it moves from their Backpack to their character model, so just change the directory and it should work.
if game.Players.LocalPlayer.Character:FindFirstChild("Axe")