hits = script.Parent.hit --This keeps track of how much "hp" the tree has left
local newtree = script.Parent:clone() --for inserting a new tree later
while true do --infinite loop
if hits.Value < 1 then --if the tree has less than 1 "hp" then
script.Parent:BreakJoints() --make tree able to fall over.
wait(3) --wait a while
script.Parent:remove() --remove the tree
wait(10) --wait a while
newtree.Parent = game.Workspace --insert a new tree
newtree:MakeJoints() --make tree unable to fall over
end
wait(1) --wait a while before checking trees hp again
end
Hello, thank you for reading! What I'm trying to do is that when a tool named "Axe" hits and takes all the tree's HP, then the tree will die and give you money. My problem is that the tree dies, and after it regenerates, it's script doesn't work. You can't kill it again. This is a new edited script I tried to do.
hits = script.Parent.hit --This keeps track of how much "hp" the tree has left
local newtree = game.Lighting.newtree2 --for inserting a new tree later
while true do --infinite loop
debounce = true
if hits.Value < 1 then
if script.Parent:isA("Model") then --if the tree has less than 1 "hp" then
script.Parent:BreakJoints() --make tree able to fall over.
wait(3) --wait a while
script.Parent:remove() --remove the tree
wait(5) --wait a while
newtree.Parent = game.Workspace --insert a new tree
newtree:MakeJoints() --make tree unable to fall over
debounce = false
end
wait(1) --wait a while before checking trees hp again
end
end
What I added was the if script.Parent:isA("Model") then part, but when I Play in the game, the server does not start. I think it is because of the while true do part, which causes the game to repeat the scripts so much the server doesn't lag.
Sorry for the long explanation, and if anyone can help me, I would be so grateful!

2 comments
You should use the Changed event and not a while loop.
How would I do that? I don't know what the Changed Event is.