What I want to achieve
When the tool hits the part the health will go down
The issue
When I hit it once with the tool’s blade, the part looses an health point, but if I do it another time, it does not work.
What I tried
I’ve looked on the devforum but wasn’t able to find any solutions.
Heres the script inside the part
script.Parent.Touched:Connect(function(hit)
if hit.Name == 'Blade' then --The blade is inside a tool
script.Parent.Parent.Health.Value -= 1 --Health
if script.Parent.Parent.Health.Value <= 0 then
--My stuff
end
end
end)
The tool is activated on click to play the animation and get the CanTouch properity on true, but I believe that this is not the problem as the sounds that plays when the tool hits the tree is in the tool script.
if theres more than 1 child in your tool, try this script (reposting this because it didn’t send on the first time)
script.Parent.Touched:Connect(function(hit)
if hit.parent.Name == 'Blade' then --The blade is inside a tool
script.Parent.Parent.Health.Value -= 1 --Health
if script.Parent.Parent.Health.Value <= 0 then
--My stuff
end
end
end)```
This is because you are checking if the health is <= to 0, which I believe is not what you intend. it should be >= if I understand your situation correctly.
The ‘’<= 0’’ is perfectly fine, my issue is that when the part in my tool touches the other part wich is in workspace, it only works once, but not twice as it is intended to.
If I remember correctly the Touched event only fires if 2 parts in the same collision group that have CanTouch set to true touch so I think your problem is that the way your blade and tool scripts are configured, there’s a chance that the blade’s CanTouch is set to false when the blade touches the tree. I suggest leaving CanTouch set to true for the blade and removing the blade’s Touched event while also removing the lines inside the Tool’s script that disables the blade’s CanTouch property because you don’t need to keep turning it off or on