How do I make the NPC turn black when dead?

I want to make it so when I kill the NPC, all its limbs turn into a Neon Black color. But I have very little to no capabilities in scripting and I don’t know how to write a script for this. I searched many tutorials on YouTube and couldn’t find anything so I would appreciate any help.

https://i.gyazo.com/4b9cb9bfa4ad97df5fbd2374e08e6b40.mp4

Recently, I found one video on Youtube but the script still wouldn’t work when I applied it to my NPC. This is what I have.

local humanoid = obj.Parent:findFirstChild("Humanoid")

if humanoid then
	if humanoid.Health < 0 then
		script.Parent.Size = script.Parent.Size/2
		script.Parent:Clone()
		humanoid.Health = 0
		for i,v in pairs(humanoid.Parent:GetChildren()) do
			if v:IsA("BasePart") then
				v.Brickcolor = BrickColor.new("Really black")
				v.Material = Enum.Material.Neon
				v.Velocity = Vector3.new(math.random(-100,100), 50,math.random(-100,100))
				
			end
		end
	end
end
1 Like

You will definitely need basic Roblox Lua knowledge to accomplish this. There are several ways to go about this, but I guess I would check Humanoid.Died event and connect that to a function the runs a for loop over the children (body parts) of the NPC and change their properties. I’m too lazy to write up code, but I hope this helps in some way.

Update:

I see you posted some code from YouTube… this code has the right idea, but you would need to redefine the path of the local variable humanoid to be the path to your NPC. Also, you would want to either recursively check if their Health property is 0, or connect the Humanoid.Died event to a function that runs the for loop in your code. Right now, this runs a series of if statements that only checks the property once. This does not accomplish what you want, but instead checks if their health is 0 one time and if it is, turns them neon black etc.

1 Like

I see. Thanks for the response and update. I think I see what you mean. I’ll see how to change this script by researching into the humanoid.died event you talked about and try to learn from tutorials.

I see you are using R15 – R15 uses MeshParts for all of the body-parts excluding the head.
Also if I were you, I would tie this to the .Died event in the Humanoid.

I find that if you put this code into a server script directly inside the NPC, it will turn it black when it dies from something damaging it. It does not seem that changing the part materials inside of the characters to neon will actually make them glow, at least not for me. I cannot offer much insight in how to fix that. You will have to tweak it to achieve everything else you have in your scripting, the cloning, size changes, and what not.

script.Parent.Humanoid.Died:Connect(function()
	for i, v in pairs(script.Parent:GetDescendants()) do
		if v:IsA("BasePart") then
			v.BrickColor = BrickColor.new("Really black")
			v.Material = Enum.Material.Neon
			v.Velocity = Vector3.new(math.random(-100, 100), 50, math.random(-100, 100))
		end
	end
end)

As you can see, the “Died” function coming from the humanoid, once it is triggered, gets the base parts from the character and changes them based on what the script determines. If you want the NPC to become completely black in color, you will also have to remove the shirt and pants from it upon dying.

1 Like