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

Not taking away health?

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)

4 comments

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.

1

Make sure the script is inside the part you want to kill the player

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.

0

OMG!! It is disabled :P

3 answers

✓ Accepted answer
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

1 comment

0

Did not work

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.

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

1 comment

0

That will not help him find the solution to his problem. He's wanting the script he already has fixed.

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