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

How do I make a script that prints something when the humanoid in a brick dies?

I keep trying this but it doesn't work. What happens instead is it auto prints "dead" even when the brick has 1000 health.

a = script.Parent
if a.Humanoid.Health==0
then
print "dead"

2 answers

I presume that you have a Humanoid in your brick. If so then create a loop checking the if statement if its health is either 0 or less than 0.

a = script.Parent
while true do
	wait(1)
if a.Humanoid.Health <=0
then
print "dead"
end
   end

1 comment

0

Try to avoid loops.

Use the died event

All Humanoids have the event called the Died Event. The event fires when the Humanoid's health gets below 1.

You could have found this event on the wiki about Humanoids and looking at their events.

Assuming a is the Humanoid...

local a = script.Parent:WaitForChild("Humanoid")

a.Died:connect(function()
	print("Died")
end)
On line one, I used WaitForChild to wait for the Humanoid. I also used a local variable by putting local in front of the variable. Both of these things are optional, but best practices.

Good Luck!

If I helped, please don't forget to accept my answer.

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