Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to make a npc like zombie for example die by script?

the npc spawns into workspace (all the same name) i can't figure out how to make the script kill npcs (even if they have the same name)

for _, descendant in pairs(game.Workspace:GetDescendants()) do
if descendant:IsA("Humanoid") then
descendant.Health = 0

4 comments

0

Maybe specify why their scripts aren't working for you instead of just saying "doesn't work"..? Both of their scripts would work in your case...

0

it snot killing the npcs, i have a script where it would disable the npc spawn (which works) but now im trying to kill the npcs that are still in workspace (alive)

0

you need to find the zombie.

0

uh...

2 answers

✓ Accepted answer

I will delete this answer if it still not working:

game.Workspace.DescendantAdded:Connect(function(brains)
	if brains.Name == "name?" then
			local findinghealth = brains:FindFirstChild("Humanoid") or brains:FindFirstChildOfClass("Humanoid") --You don't want errors right?
		if findinghealth then
findinghealth.Health = 0
		print("Zombie is killed! Hooray!")
end
	end
if not brains.Name == "same as the zombie's name please" then
warn("You found a wrong zombie! Try again please! --cherrythetree")
end
end)

This first find the name of the zombie then finds if the zombie has health.

The event DescendantAdded will function if a part/model/etc. is added in game.Workspace. And you notice that there is brains* after function.

Example: brains* has a mission to find a object's name like for example: "Drooling Zombie" then he found one and killed the zombie by finding its health.

###You would check the name property, instead of checking if they are or inherit from the Humanoid class.

for _, descendant in pairs(workspace:GetDescendants()) do
    if descendant.Name == 'name here' then -- insert name 
        -- do something 
    end
end

2 comments

0

doesn't work ;/

0

I am still gonna upvote this thought.

This discussion is preserved as it was. New answers, comments, and votes are closed.