Need some help on the custom npc I made

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.


and here is my npc I am trying to make
image
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!

Can you send the script formatted?

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

Does the npc walk?

So what is the problem with this script, it should work fine

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.

no transparency is only 1 and its the max

Put a if statement, maybe the npc detects himself :person_shrugging:

Try this:

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

Mark as solution if helps

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.

actually nevermind what found out was the error on my other script thanks for your help (Ill prob delete this if incase it does not work)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.