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)
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.
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)