Im trying to make a script so when you finish chopping it, it deletes itself and then after some time goes back to orginal state, But when it does go back to its orginal state it gets the mesh of a different tree? There are no errors
if health.Value == 0 or health.Value < 0 then
workspace.Treehit:Play()
print(health.Value)
wodas()
tree.Tree.Anchored = false
tree.Tree.CanTouch = false
goi.CanvasGroup.Visible = false
goi.CanvasGroup.Amount.Size = UDim2.new(0,0,0,75)
amount:Destroy()
game.ReplicatedStorage.AddWood:FireServer()
local newtree = hit.Parent -getting oldtree
tree:Destroy() -deling old tree
wait(2)
newtree:Clone() -cloning tree
newtree = workspace
newtree.Tree.Tree.CFrame = CFrame.new(oldpos)
newtree.Tree.Tree.Anchored = true
newtree.Tree.Tree.CanTouch = true
newtree.Tree.Health.Value = newtree.Tree.Maxhealth.Value
newtree.Tree.DamageDelt.Value =0
db = true
return
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
I’m pretty sure it would be easier if you cloned the newtreebefore deleting the destroyed tree?
So, you clone it, and hide it since collisions are already disabled. This might save you time from generating new trees.
...
local newtree = hit.Parent:Clone()
newtree.Parent = hit.Parent -- recommended to set parent of cloned item again
newtree.Transparency = 1
-- or use a for loop if there are dependencies, basiacally hide it from the world
tree:Destroy();
wait(2)
newtree.Transparency = 0;
-- or for loop to make it visible after the old tree is destroyed
You have a problem that the new tree isn’t the same as the previous tree.
You need to change your script a bit to fix the issue or don’t do anything? It’s do or don’t, your choice though.
As I said above, it’s recommended to bulk rename all the trees with a studio command line script, or rename the tree after it is destroyed - which can still cause problems even after you rename it in game.
Renaming is simple following this sample:
for n, tree in pairs(workspace:Getchildren()) do if tree.Name == "Tree" then tree.Name = "Tree"..tostring(n) end end
This will add a “unique” number to every of your trees so there won’t be any confusion