What I am trying to do is to change the part’s transparency and enabling/disabling the script inside it. Whenever a humanoid has 30 or less health left, the part’s transparency will be 0 and the script is enabled. However, if a humanoid has exactly 30 or more health left, the part’s transparency will be 1 and the script is disabled. I tried some ways but it did not work. The part I am trying to use it on is HealArea. Here is my script so far.
The HealArea is basically the forcefield around it.
Now I might confuse you since I cant explain accurately, so If you are confused you can freely ask me. Also my messages sometimes are long to respond so please be patient. Thanks!
NPCCheck = script.Parent:FindFirstChild("Torso")
if NPCCheck == nil then
warn("Does not have a torso")
script:remove()
else
print("The AI is ready")
end
local human = script.Parent.Humanoid
while wait() do
for _, child in pairs(workspace:GetChildren()) do
if child:IsA('Model') and child:FindFirstChild('Humanoid') and (script.Parent.Torso.Position - child.Torso.Position).magnitude < 30 then
script.Parent.Humanoid.WalkSpeed = 20
human:MoveTo(child.Torso.Position)
script.Parent.Torso.Touched:connect(function()
human.Jump = true
end)
if human.Health < 30 then
script.Parent.HealArea.Script.Enabled = true
script.Parent.HealArea.Transparency = 0
else
script.Parent.HealArea.Script.Enabled = false
script.Parent.HealArea.Transparency = 1
end
end
end
end
the npc walks but the forcefield around it needs to be transparent when it detects a player if they have over than 30 hp and the script needs to be disabled. However if the player has less than 30 hp it will be visible and the script that heals the player needs to be enabled.
NPCCheck = script.Parent:FindFirstChild("Torso")
if NPCCheck == nil then
warn("Does not have a torso")
script:remove()
else
print("The AI is ready")
end
local human = script.Parent.Humanoid
while wait() do
for _, child in pairs(workspace:GetChildren()) do
if child:IsA('Model') and child:FindFirstChild('Humanoid') and (script.Parent.Torso.Position - child.Torso.Position).magnitude < 30 and (script.Parent.Torso.Position - child.Torso.Position).magnitude > 0.5 then
script.Parent.Humanoid.WalkSpeed = 20
human:MoveTo(child.Torso.Position)
script.Parent.Torso.Touched:connect(function()
human.Jump = true
end)
if human.Health < 30 then
script.Parent.HealArea.Script.Enabled = true
script.Parent.HealArea.Transparency = 0
else
script.Parent.HealArea.Script.Enabled = false
script.Parent.HealArea.Transparency = 1
end
end
end
end
It didnt work but I found out that when you are below 30 hp then it wont change the transparency at all so what I looked for is while the npc is following you it changes the transparency of the HealArea whenever you have 30 or below health left.