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

Can somone help with this script?

Asked by
NexeusX 137
8 years ago

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

Log in to vote
0
Answered by 8 years ago

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!

0
Make sure to accept an answer btw. User#11440 120 — 8y
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 DevSean 270 — 8y
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. NexeusX 137 — 8y
Ad
Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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.

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. Kryddan 261 — 8y
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 NexeusX 137 — 8y

Answer this question