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

Can somone help with this script?

So i am trying to get this script to call a function when the humanoids health is at "0" but when i run it, it doesn't do anything even though the function is a simple "print Word" into the output, why is it not working?

if script.Parent.Humanoid.Health == 0 then
	PrintWord()
end


function PrintWord()

print 'Hello world!'

end

2 answers

✓ Accepted answer

Pyrondon's script will work, but it's not as simple as you could make it. Instead of using two functions you only have to use one. Here's what you could do much more easily,

script.Parent.Humanoid.Changed:connect(function(health)--Health is the propertie that changed. It also makes a variable that we use below.
     if health == 0 then
          Print"Hello World!" --do what you were doing in your function here.
     end
end)

This is just simplified. If you like having two functions that's up to you and you should use Pyrondon's script. Hope I helped!

3 comments

0

Make sure to accept an answer btw.

1

This is worse, what happens if WalkSpeed, HealthDisplayDistance, HipHeight and NameDisplayDistance etc. etc. change to zero. Instead you should use HealthChanged: http://wiki.roblox.com/index.php?title=API:Class/Humanoid/HealthChanged

0

I had to make a few adjustmentst to this simplified script, for some reason it didnt want to run? But i just removed the variable and now it works fine thanks for the help guys.

In the future, please be more descriptive about your problem in the title.

Your problem is that the script only checks once. You can fix this by connecting a function to the .Changed event.

function PrintWord()
     print 'Hello world!'
end

script.Parent.Humanoid.Changed:connect(function()
     if script.Parent.Humanoid.Health == 0 then
          PrintWord()
     end
end)

Please excuse any grammatical errors I may have made; I am mobile right now.

Hope this helped.

2 comments

0

Just a quick note if @T23R doesn't know what .Changed does, it basically executes the function everytime a property/value of a object changes.

0

Ok thanks for the help a lot, sorry about my title question i don't think somtimes -.- and thanks for showing the ".Changed" thats somthing i will use in a lot of my scripting

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