generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Does the changed event work for a humanoid's Health?

Previous Thread :: Next Thread 
jtefurd is not online. jtefurd
Joined: 01 May 2010
Total Posts: 952
30 May 2015 08:37 PM
Will a script updated every time a humanoid's health changes with the changed event?
game.Player1.Humanoid.Changed:connect(function()
print(game.Player1.Humanoid.Health)
end)
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
30 May 2015 08:38 PM
I think so, why not test it instead?
Report Abuse
jtefurd is not online. jtefurd
Joined: 01 May 2010
Total Posts: 952
30 May 2015 08:41 PM
I have with a health overlay gui. It won't update with the humanoid's health.
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
30 May 2015 08:44 PM
Yes.
Report Abuse
jtefurd is not online. jtefurd
Joined: 01 May 2010
Total Posts: 952
30 May 2015 08:48 PM
This script is in a frame in a playergui.

player = game.Players.LocalPlayer
MaxHealth = player.Character.Humanoid.MaxHealth;Health = player.Character.Humanoid.Health

player.Humanoid.Changed:connect(function()
if Health < MaxHealth then
script.Parent.BackgroundTransparency = 1-((.20*Health)/MaxHealth)
elseif Health == MaxHealth then
script.Parent.BackgroundTransparency = 1
end
end)

Report Abuse
jtefurd is not online. jtefurd
Joined: 01 May 2010
Total Posts: 952
30 May 2015 08:49 PM
It's not updating at all.
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
30 May 2015 08:57 PM
Health isn't a member of player. Here is a tutorial for you:

http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting
Report Abuse
jtefurd is not online. jtefurd
Joined: 01 May 2010
Total Posts: 952
30 May 2015 09:01 PM
I saw that. I changed it to:

local player = game.Players.LocalPlayer
MaxHealth = player.Character.Humanoid.MaxHealth;Health = player.Character.Humanoid.Health
player.Character.Humanoid.Changed:connect(function()
if Health < MaxHealth then
script.Parent.BackgroundTransparency = 1-((.20*Health)/MaxHealth)
elseif Health == MaxHealth then
script.Parent.BackgroundTransparency = 1
end
end)

Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
30 May 2015 09:39 PM
Wait for the humanoid to exist. Also use HealthChanged:

humanoid.HealthChanged:connect(function(health)
print(health)
end)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
30 May 2015 09:49 PM
try this

local player = game.Players.LocalPlayer
local char = player.Character
local human = char:FindFirstChild("Humanoid")

human.Changed:connect(function()
if human.Health < human.MaxHealth then
script.Parent.BackgroundTransparency = 1-((0.20*human.Health)/human.MaxHealth)
elseif human.Health == human.MaxHealth then
script.Parent.BackgroundTransparency = 1
end
end)
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
30 May 2015 09:51 PM
^
Use WaitForChild.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
30 May 2015 09:52 PM
@nq no I was just too lazy to add the checks.

local player = game.Players.LocalPlayer
local char = player.Character
local human = char:FindFirstChild("Humanoid")

if player and char and human then
human.Changed:connect(function()
if human.Health < human.MaxHealth then
script.Parent.BackgroundTransparency = 1-((0.20*human.Health)/human.MaxHealth)
elseif human.Health == human.MaxHealth then
script.Parent.BackgroundTransparency = 1
end
end)
end
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
30 May 2015 09:52 PM
XD

Almost no one knows about HealthChanged eh.


I script -~ chimmihc
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
30 May 2015 09:53 PM
You should still be using WaitForChild.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
30 May 2015 09:57 PM
No I shouldn't "need" to. I do what I want.
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
30 May 2015 09:58 PM
Alright well it's a pretty cool non-working script then, but you do what you want.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image