0
votes

So I made a tree in roblox that you can break so far and the part dissapears. I want to make it regenerate after about a minute. Here is the script. How would I do this? I see a lot of people have regenerating buttons and I would like to make a tree that regenerates at 60 seconds, Im aware you have to do something with wait (60) and some position stuff but I have no clue after that

local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Mouse = Plr:GetMouse()
local CouldGetWood = true

function ShowProgress(tree)
 if tree == "Tree" then
  for i = 0,1,.01 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 elseif tree == "HardTree" then
  for i = 0,1,.005 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 end
end

Mouse.Button1Down:connect(function()
 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "Tree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.UpperTorso.Position).magnitude < 10 then
   CouldGetWood = false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("Tree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   WC.BG.Visible = false
   CouldGetWood = true
  end
 end

 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "HardTree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.Torso.Position).magnitude < 10 then
   CouldGetWood= false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("HardTree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   WC.BG.Visible = false
   CouldGetWood = true
  end
 end
end)```






1

1 Answers

0
votes

Here is a cheap thing you can do: Before you start chopping down the branch, make a backup of it. Then later after you destroy the original, just wait a few seconds and put the backup in place.

So in your script after

if (Wood.Position - Char.UpperTorso.Position).magnitude < 10 then

you add:

local tree = Mouse.Target.Parent
local backupWood = Wood:clone()

this will create a backup of that wood and its child parts. Then after destroying the wood at the end of the function, you add:

spawn(function()
    wait(60)
    backupWood.Parent = tree        
end)

This will spawn a new thread, so that your mouse handler thread can continue. In that thread, after waiting for 60 seconds, you hooking your backup part to the tree part, by setting the Parent property, thus making it visible.