I’m trying to make a pickaxe that destroys ores using the player’s mouse target. But I ran into a problem. Any help or feedback would be appreciated! ![]()
Script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local pickaxe = script.Parent
local animation = replicatedStorage:WaitForChild("Visuals"):WaitForChild("Animations"):WaitForChild("PickaxeSwing")
local debounce = false
local cooldown = 1
pickaxe.Activated:Connect(function()
if debounce == false then
debounce = true
local char = pickaxe.Parent
local hum = char.Humanoid
local animator = hum.Animator
local plr = players:GetPlayerFromCharacter(char)
local mouse = plr:GetMouse()
local track = animator:LoadAnimation(animation)
track:Play()
if mouse.Target and mouse.Target.Parent then
if mouse.Target.Parent:IsA("BasePart") and mouse.Target.Parent:HasTag("Ore") then
mouse.Target.Parent:Destroy()
end
end
wait(cooldown)
debounce = false
end
end)
Error: Workspace.Pickaxe.Script:24: attempt to index nil with ‘Target’ - Server - Script:24