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

Why doesn't it kill the character?


Killer = script.Parent


Killer.Touched:Connect(function()
	
game.Players.FindFirstChild.Humanoid.Health = 0
end)

1 comment

0

I'm still new, and I am willing to learn

1 answer

✓ Accepted answer

First of all you'll need to gain access to the player's character in order to take their health away like so(I'll assume its a normal script):

Killer = script.Parent
Killer.Touched:Connect(function(hit) -- hit will be whatever has touched the part (e.g left leg, etc)
if hit.Parent:FindFirstChild("Humanoid") then -- we need to make sure it was a character
hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 100 -- Takes all their health.
end
end)

Any errors will likely be on your end, e.g not placing the script in the appropriate place.

6 comments

0

Killer = script.Parent

0

What?

0

Variable names are supposed to be lowecase, and every next word begind with a captial letter: likeThisYouBagel

1

Also, your spacing hurts, please fix it.

3

@iSpaceRBLX if you're not accurately contributing to the discussion, don't comment dude.

1

@iSpaceRBLX yes I am well aware of “Camel Casing”. “Variable names are suppose to be lowercase” i didn’t know my code would error if I didn’t follow this rule. Thanks for the insight really appreciate it.

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