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

Not taking away health?

Asked by
FiredDusk 1466 Moderation Voter
9 years ago

I don't understand why it does not kill me.

function Touched(hit) --"Touched" is name of the function.

    local hum = hit.Parent:findFirstChild("Humanoid")

    if hum then
        hum.Health = 0
    end
end

script.Parent.Touched:connect(Touched)

1
Script works on my end, are you getting any errors? In studio tell us any errors related to the script from the output or in game hit F9 and tell us any errors related to the script from there. M39a9am3R 3210 — 9y
1
Make sure the script is inside the part you want to kill the player YellowoTide 1992 — 9y
2
I tested the script seems to work perfectly fine. Are sure the script you're using isn't disabled or even using a Local Script. The only other reason I could think of for the script not to work is if a third party script renames the Humanoid. UserOnly20Characters 890 — 9y
0
OMG!! It is disabled :P FiredDusk 1466 — 9y

3 answers

Log in to vote
0
Answered by
Udrii 0
9 years ago
function Touched(hit)
    local parent = hit.Parent
    if game.Players:GetPlayerFromCharacter(parent) then
        parent.Humanoid.Health = 0
    end
end

script.Parent.Touched:connect(Touched)

alternative for only players not npc's

0
Did not work FiredDusk 1466 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

To make things easier, just have the function be triggered at the beginning.

script.Parent.Touched:connect(function(hit)
    local humanoid = hit.Parent:WaitForChild("Humanoid") .
    if humanoid then
        humanoid.Health = 0
    end
end

I prefer using a WaitForChild when I'm using a script that requires something to be found before the following code should be ran.

Log in to vote
-3
Answered by 9 years ago

you could use the same code as the dreaded "kill brick"

0
That will not help him find the solution to his problem. He's wanting the script he already has fixed. M39a9am3R 3210 — 9y

Answer this question