local tree = script.Parent local health = 10 if health == 0 then tree.Position = Vector3.new(-52.751, 50.888, -54.404) end tree.Touched:connect(function(hit) if hit.Name == "Blade" then health = health - 1 print("Player Has Cut Tree") end end)
there are no errors
Your code is only checking the health once. The script reads what you've written up to tree.Touched:connect... once and then just listens for the tree being touched, every time the tree is touched the code in that funciton runs. So just have the script check the health everytime the tree is touched :)
local tree = script.Parent local health = 10 tree.Touched:connect(function(hit) --when the tree is touched... if hit.Name == "Blade" then --if hit by a blade then... health = health - 1 --take 1HP print("Player Has Cut Tree") if health == 0 then --check if the HP has reached 0 tree.Position = CFrame.new(tree.Position) + Vector3.new(-52.751, 50.888, -54.404)) else print(health) --prints the curent HP of the tree end end end)
Hopefully that is clear and works alright... :) Best of luck, let me know if this helped!
OK what your doing wrong is it will only check once if the health is 0. At the beginning it's 10. What you have to do is this:
local tree = script.Parent local health = 10 while true do if health == 0 then tree.Position = Vector3.new(-52.751, 50.888, -54.404) end wait() end tree.Touched:connect(function(hit) if hit.Name == "Blade" then health = health - 1 print("Player Has Cut Tree") end end)
You've done 3 things wrong 1 a debouncer 2 detecting if the health is still 0 when touched 3rd you should have a Detector for when the health reaches 0
local tree = script.Parent local health = 10 local Debounce = true game:GetService("RunService").Heartbeat:Connect(function() if health == 0 then tree.Position = Vector3.new(-52.751, 50.888, -54.404) end end) tree.Touched:connect(function(hit) if Debounce == false then return end if hit.Name == "Blade and health >0" then Debounce = false health = health - 1 wait(0) ---Change time if want the wait to chop it again to be longer Debounce = true end end)