How do I make a part respawn after a minute once it gets destroyed

When the ore (part) gets mined it will get destroyed by line 42, how do I make it respawn after 60 seconds?

Script:

local pickaxe = script.Parent
local head = pickaxe:WaitForChild("Head")
local mouseHeldRE = pickaxe:WaitForChild("MouseHeldEvent")
local mouseHeld = false
local coolingDown = false


mouseHeldRE.OnServerEvent:Connect(function(isHeld)

	mouseHeld = isHeld	
end)


head.Touched:Connect(function(hitPart)

	if not mouseHeld or coolingDown then return end

	coolingDown = true
	

	local blockStrength = hitPart:FindFirstChild("HitsToBreak")

	if blockStrength then

		blockStrength.Value = blockStrength.Value - 1

		
		if blockStrength.Value <= 0 then 


			local plr = game.Players:GetPlayerFromCharacter(pickaxe.Parent)

			plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + hitPart.CashReward.Value


			hitPart:Destroy() 
		end
	end

	wait(0.9)

	coolingDown = false
end)

What youā€™ll want to use is task.delay:

task.delay(60, function()
-- respawn code
end)

simply move it to server/replicatedstorage when it gets ā€˜minedā€™, add a wait(60), and then return it to workspace.

Where would I add the wait(60) in the script?

Behind the coolingdown = false should work as you want

How do I move it to server storage when mined? and is there a youtube video on how to do it

If you do not know the answer to this question, you should really really consider looking through basic tutorials/intros to roblox scripting.

You set the .Parent property of the brick to game.ServerStorage or game:GetService("ServerStorage") - keep in mind you have to use replicatedstorage in the case itā€™d be a localscript.

Assuming the script would clone from the games storage, you can just make the script delete the part that is touchable, then clone the part from the games storage, then the script will delete the parent leaving you with a new clone part after 60 seconds.
Reusing the same model, like changing itā€™s parents back and forth, may cause problems but thatā€™ll also work instead of just destroying the part too.

You could try using something along the lines of

while true do
wait()
if not workspace:FindFirstChild(ā€œpartnameā€) then
ā€”put some code here
end
end

probably too late but

repeat wait() until script.Parent ~= workspace
local a = script.Parent:Clone()

local w = script.Parent.Parent
local dltd = script.Parent
script.Parent = game.Workspace
dltd.Destroying:Connect(function()
	script:Destroy()
	wait(math.random(1,3))--respawn time
	a.Parent = w

	script.Enabled = false
end)

1 Like

Why did you revive a 3 year old post I thought this was new :sob:

2 Likes