Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check if player clicks with a tool?

Asked by 6 years ago
Edited 6 years ago

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
0
there is a event of the tool called Activated(tool.Activated:Connect(funtion())... theking48989987 2147 — 6y
0
Hi, now i have the problem that when i hold a tool i cant click it anymore :( Alwaysrube 22 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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") 
Ad

Answer this question