How to make a tree respawn system

Hello! :grinning:

I’ve been creating a game about chopping trees. I finished working on the tree chopping aspect, now I just need a way to respawn the tree after one has been cut. Here’s my problem, I have no idea how I would do this, I am unsure how I would check if a tree has been destroyed, what type of tree, etc. I am pretty boned on knowledge here because I simply can’t find anything related to my issue.

Help would be appreciated.

3 Likes

In first line of ur tree code (or in a new script), clone the tree

Every X time, put the clone in workspace and delete the tree, for example

local ttime = 60
local tree = script.Parent:Clone()

while true do
   task.wait(ttime)
   tree.Parent = script.Parent.Parent
   script.Parent:Destroy()
end

If you want to only respawn if being cut, do a bool value inside the tree and turn it on when the tree got cut, and it gonna be

local ttime = 10
local tree = script.Parent:Clone()
local Value = script.Parent.Value

Value.Changed:Connect(function()
   task.wait(ttime)
   tree.Parent = script.Parent.Parent
   script.Parent:Destroy()
end)

(I put “ttime” instead of “time”, because “time” is already a function that can’t be used like a Value)

-- Variables
local Tree = script.Parent 
local ServerStorage = game:GetService("ServerStorage") -- gets serverstorage
local TweenService = game:GetService("TweenService") -- Gets tween service
local Health = Instance.new("NumberValue") -- makes a number value
Health.Parent = Tree -- makes tree the parent
Health.Value = math.random(10,15) -- makes a random value for the number value which is the health
local goal = (
Transparency = 1
)

Health:GetPropertyChangedSignal("Value"):Connect(function() -- Detects if Health.Value changed
if Health.Value <= 0 then -- Checks if the health is equal to 0 or less
local NewTree = Tree:Clone() -- clones tree
NewTree.Parent = ServerStorage -- puts new tree in server storage
for i, v in pairs(Tree:GetDesendents()) do -- gets the children of tree
if v:IsA("Part") then -- checks if its a part
v.CanCollide = false -- turns part collision false
local PartTween = TweenService:Create(v, TweenInfo.new(2) -- amount of seconds for it to fully become transparent, goal) -- Uses tween service to make the transparency to 1.
PartTween:Play()
task.wait(2) -- task.wait() is more accurate than wait() and its recommended to start using task.wait()
v:Destroy() -- Destroys part
end
end
task.wait(math.random(20,30) -- uses math.random to make choose a random value between 20 and 30
NewTree.Parent = game.Workspace -- puts the new tree in workspace
script.Parent:Destroy() -- destroys original tree
end
end)