Hey there,
I’m trying to create a tool that when clicked on an object with (in this instance, a tree) it would damage the tree, but my script doesn’t seem to work or give any errors.
I’ve tried adding prints to see where the issue is, and it seems to only make it up to line 13, so I assume it’s something to do with the Mouse.Target
Any help wouuld be appreciated, thank you!
Here is the script (localscript inside the tool)
wait()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char.Humanoid
local anim = hum:LoadAnimation(script.Parent.SwingAnim)
local mouse = player:GetMouse()
local tree = game.Workspace.Map.Biomes.Grasslands.Trees.Oak
local cooldown = false
script.Parent.Activated:Connect(function()
if script.Parent.Equipped then
if mouse.Target == tree then
if cooldown == false then
print('Code works!')
anim:Play()
cooldown = true
wait(1.5)
cooldown = false
end
end
end
end)