Mining System Not Working

  1. What do you want to achieve? Keep it simple and clear!

I want to make a pickaxe which can mine ores

  1. What is the issue? Include screenshots / videos if possible!

The first ore you break with the pickaxe works, but the second ore doesnt

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried looking for other posts on the DevForum but I couldn’t find any

Script:

local plr = game.Players.LocalPlayer
local char = plr.Character

local mouse = plr:GetMouse()

local tool = script.Parent

local Mine = tool:WaitForChild("Mine")
local MTrack = char.Humanoid.Animator:LoadAnimation(Mine)

local mining = false

local TS = game:GetService("TweenService")

local function RespawnTargetOre(target)
	local TClone = target:Clone()
	target:Destroy()
	task.wait(30)
	TClone.Parent = workspace.Map.Ores
end

tool.Activated:Connect(function()
	local target = mouse.Target.Parent
	
	if not mining then
		mining = true
		MTrack:Play()
		if target:FindFirstChild("HP") and target:FindFirstChild("MaxHP") then
			if target:FindFirstChild("HP").Value == 1 then
				task.spawn(RespawnTargetOre(target))
			else
				target:FindFirstChild("HP").Value -= 1
				if not target:FindFirstChild("HealthBar") then
					local HBar = game.ReplicatedStorage.HealthBar:Clone()
					HBar.Parent = target
				end
				TS:Create(target.HealthBar.Frame.Frame, TweenInfo.new(0.25, Enum.EasingStyle.Quad), {Size = UDim2.new(target.HP.Value/target.MaxHP.Value,0,1,0)}):Play()
			end
		end
		MTrack.Stopped:Wait()
		mining = false
	end
end)

Thanks!

This may be the issue.
task.spawn takes the function itself as the first parameter, then the arguments as the second parameter, so it instead be

task.spawn(RespawnTargetOre, target)

Thank you so much! This really helped me!