I am working on a base that is going to have a wall that can be attacked and when its hit points hit 0 it will disappear. I have made a model and added the part and a humanoid part as well. I am not sure why the block will not disappear when its hit points hit 0. can anyone help me please...
if Script.Parent.Humanoid.Health > 0 then do Script.Parent.Part.Transparency = 0 Script.Parent.Part.CanCollide = true if Script.Parent.Humanoid.Health <= 0 then do Script.Parent.Part.Transparency = 1 Script.Parent.Part.CanCollide = false end
as well if you have a better code feel free to share.
ok, revised issues.....
This is what I have now it works kind of....
It will change one block transparency and not the others.
help please... lol
this is how it is set up
Workspace
Model Script Model Model Model Model Model Model Model
This is the script
for i,v in pairs(script.Parent:GetChildren()) do if not v:IsA("Script") then v.Humanoid.Changed:connect(function() if script.Parent.Model.Humanoid.Health > 0 then script.Parent.Model.Part.Transparency = 0 script.Parent.Model.Part.CanCollide = true elseif script.Parent.Model.Humanoid.Health <= 0 then script.Parent.Model.Part.Transparency = 1 script.Parent.Model.Part.CanCollide = false end end) end end
You had a few syntax errors..
script.Parent.Humanoid.Changed:connect(function() if script.Parent.Humanoid.Health > 0 then script.Parent.Part.Transparency = 0 script.Parent.Part.CanCollide = true elseif script.Parent.Humanoid.Health <= 0 then script.Parent.Part.Transparency = 1 script.Parent.Part.CanCollide = false end end)
Oh! You never said you wanted all the blocks to become invisible! Here's the fixed one!
for i,v in pairs(script.Parent:GetChildren()) do if not v:IsA("Script") then v.Humanoid.Changed:connect(function() if v.Humanoid.Health > 0 then v.Part.Transparency = 0 v.Part.CanCollide = true elseif v.Humanoid.Health <= 0 then v.Part.Transparency = 1 v.Part.CanCollide = false end end) end end)