I need to make a tree change it’s parent when broken/Health. Value = 0
It doesn’t sense when the Health reaches 0
I tried while true do but it still didn’t work
Script:
Health:GetPropertyChangedSignal("Value"):Connect(function()
if Health.Value <= 0 then
tree.Parent = game.ReplicatedStorage.BrokenObjects
Health.Value = MaxHealth
wait(180)
tree.Parent = game.Workspace.Objects
local clone1 = drop1:Clone()
clone1.Parent = game.Workspace
clone1.Position = tree.Position
local clone2 = drop1:Clone()
clone2.Parent = game.Workspace
clone2.Position = tree.Position
local clone3 = drop2:Clone()
clone3.Parent = game.Workspace
clone3.Position = tree.Position
end
wait()
end)
local Tree = script.Parent
local Health = script.Parent:WaitForChild("Health")
local MaxHealth = script.Parent:WaitForChild("MaxHealth")
Health:GetPropertyChangedSignal("Value"):Connect(function()
if Health.Value <= 0 then
Tree.Parent = game.ReplicatedStorage.BrokenObjects
Health.Value = MaxHealth.Value
print("Dead")
end
wait()
end)
Maybe try setting a PrimaryPart on the the tree and then saying clone1.Position = tree.PrimaryPart.Position
or clone1.PrimaryPart.Position = tree.PrimaryPart.Position if the log is also a model
Usually you’d want to move models by their PrimaryPart so it could be causing the issue, also wouldn’t you want to drop the logs before the 180 second wait period?
I guess technically you could just put the trees in a folder or something in workspace and do this
local Trees = game.Workspace:WaitForChild("Trees")
for _, Tree in pairs(Trees:GetChildren()) do
if Tree then
Tree.Health.Changed:Connect(function(Value)
if Value <=0 then
Tree.Parent = game.ReplicatedStorage.BrokenObjects
local Log1 = game.ReplicatedStorage.Log:Clone()
Log1.Parent = game.Workspace
Log1.PrimaryPart.Position = Tree.PrimaryPart.Position
local Log2 = game.ReplicatedStorage.Log:Clone()
Log2.Parent = game.Workspace
Log2.PrimaryPart.Position = Tree.PrimaryPart.Position
local Log3 = game.ReplicatedStorage.Log:Clone()
Log3.Parent = game.Workspace
Log3.PrimaryPart.Position = Tree.PrimaryPart.Position
wait(180)
Tree.Parent = game.Workspace.Trees
Tree.Health.Value = Tree.MaxHealth.Value
end
end)
end
end
Should work fine as long as the Tree model and Log model have a primary part