Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make an NPC kill you?

Asked by 8 years ago

I'm making an NPC Tag game and I need the player to die when he/she touches the NPC. But when I spawn, the NPC is already dead. Anyone know how to fix this?

Here is the script. I put in every part of the NPC (Torso, arms, legs, head)

function onTouched(hit)
    if not hit or not hit.Parent then return end
    local human = hit.Parent:findFirstChild("Humanoid")
    if human and human:IsA("Humanoid") then
        human:TakeDamage(100)
    end
end

script.Parent.Touched:connect(onTouched)

3 answers

Log in to vote
1
Answered by 8 years ago

EDIT I did not notice the fact that you were having with the NPC... Double check these things:

The maxHealth matches the Humanoid's Health The NPC has these objects: Head Humanoid LeftArm LeftLeg RightArm RightLeg Torso ** I try not to make a habit of posting the code itself, but rather telling you what needs to be done to leave it up to your own problem solving skills that way in the end, it is all your work and you learn from it.

Your if statement on Line 4 does not need to have an "and" conditional. if human:isA("Humanoid") should work. Instead of using human:TakeDamage maybe try removing a vital piece of the character, like the head or torso, or you could try setting the health property of the humanoid to 0 or a negative number and kill the player that way.

Hope this helped. Let me know if there is anything I can clarify on.

Ad
Log in to vote
0
Answered by 8 years ago

Seriously, that is way to complicated. Here is something more simple:

function onTouch(p)
if p.Parent.Humanoid~= nil then
p.Parent.Humanoid:TakeDamage(100) 
end
end
script.Parent.Touched:connect(onTouch)
0
Wait, you say the NPC is already dead. Does the NPC have the following: Humanoid, LeftArm, RightArm, LeftLeg, RightLeg, Torso, and a Head? and the humanoid health is 100 and maxhealth is 100 as well. rollercoaster57 65 — 8y
0
@rollercoaster57 Yep, it has all of those OmegaAlpha250 0 — 8y
Log in to vote
0
Answered by 8 years ago

What I think happened is it might've "touched" itself and "killed" itself, as you didn't include anything to cancel that, assuming it might've happened.

Answer this question