Avocation
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 107 |
|
|
| 20 Jun 2014 10:56 AM |
I need help this script only works once when your health changes how do I fix it?
local char = script.Parent.Parent.Parent.Parent.Parent.Character hum = char.Humanoid hum.Changed:connect(function() script.Parent.Health.Frame.Size = UDim2.new(1, 0, hum.Health/hum.MaxHealth, 0) if hum.Health <= hum.MaxHealth*0.15 then script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(150, 0, 0) else script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(0, 185, 0) end end) |
|
|
| Report Abuse |
|
|
WolfzBoii
|
  |
| Joined: 29 Jul 2013 |
| Total Posts: 135 |
|
|
| 20 Jun 2014 10:57 AM |
| Maybe add while true do at the beginning? |
|
|
| Report Abuse |
|
|
moryo7
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 5028 |
|
|
| 20 Jun 2014 10:59 AM |
local char = script.Parent.Parent.Parent.Parent.Parent.Character hum = char.Humanoid locked = false hum.Changed:connect(function() if locked == false then locked = true script.Parent.Health.Frame.Size = UDim2.new(1, 0, hum.Health/hum.MaxHealth, 0) if hum.Health <= hum.MaxHealth*0.15 then script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(150, 0, 0) else script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(0, 185, 0) end end end)
|
|
|
| Report Abuse |
|
|
moryo7
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 5028 |
|
|
| 20 Jun 2014 10:59 AM |
| OH, you wanted it not to only work once, my bad. I'll make a new one. :P |
|
|
| Report Abuse |
|
|
TheProM
|
  |
| Joined: 27 Mar 2013 |
| Total Posts: 436 |
|
|
| 20 Jun 2014 11:04 AM |
while true do local char = script.Parent.Parent.Parent.Parent.Parent.Character hum = char.Humanoid hum.Changed:connect(function() script.Parent.Health.Frame.Size = UDim2.new(1, 0, hum.Health/hum.MaxHealth, 0) if hum.Health <= hum.MaxHealth*0.15 then script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(150, 0, 0) else script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(0, 185, 0) end end) end |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:05 AM |
Does this work?
local char = script.Parent.Parent.Parent.Parent.Parent.Character hum = char.Humanoid while true do hum.Changed:connect(function() script.Parent.Health.Frame.Size = UDim2.new(1, 0, hum.Health/hum.MaxHealth, 0) if hum.Health <= hum.MaxHealth*0.15 then script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(150, 0, 0) else script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(0, 185, 0) end end) end |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:07 AM |
@TheProM
No need to redefine variables.. |
|
|
| Report Abuse |
|
|
TheProM
|
  |
| Joined: 27 Mar 2013 |
| Total Posts: 436 |
|
| |
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 20 Jun 2014 11:17 AM |
| Why would you put while true do -_- |
|
|
| Report Abuse |
|
|
Avocation
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 107 |
|
|
| 20 Jun 2014 11:56 AM |
| I tried zsoltisawesome's but roblox isn't loading with it I'll try with the while true do now xD |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:57 AM |
ERM! big screwup on my part, forgot to tell it to sleep the loop, ROBLOX crashes otherwise:
local char = script.Parent.Parent.Parent.Parent.Parent.Character hum = char.Humanoid while true do wait(0.1) hum.Changed:connect(function() script.Parent.Health.Frame.Size = UDim2.new(1, 0, hum.Health/hum.MaxHealth, 0) if hum.Health <= hum.MaxHealth*0.15 then script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(150, 0, 0) else script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(0, 185, 0) end end) end
^ that should work |
|
|
| Report Abuse |
|
|
Avocation
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 107 |
|
| |
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 20 Jun 2014 12:29 PM |
| Why is there a while loop -_- |
|
|
| Report Abuse |
|
|
Avocation
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 107 |
|
|
| 20 Jun 2014 12:40 PM |
| While true do is an infinite loop so I guess it makes it repeat the search for a health change? |
|
|
| Report Abuse |
|
|
Locard
|
  |
| Joined: 13 Apr 2014 |
| Total Posts: 3516 |
|
|
| 20 Jun 2014 12:45 PM |
All of you that have just posted a while loop do not know how to code efficiently. I'm sorry, but it's true. Here, try this:
local player = script.Parent.Parent.Parent.Parent.Parent player.Character.Humanoid.Changed:connect(function(prop) if prop == "Health" then script.Parent.Health.Frame.Size = UDim2.new(1,0,player.Character.Humanoid.Health/player.Character.Humanoid.MaxHealth,0) if player.Character.Humanoid.Health <= player.Character.Humanoid.MaxHealth*.15 then script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(150/255,0,0) else script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new(0,185/255,0) end end end)
The one you had before runs every time Humanoid has changed, which us quite literally all the time. The one I gave you makes it run only when it's the property 'Health' that changed. |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 20 Jun 2014 12:50 PM |
| All of you that have just posted a while loop do not know how to code efficiently. I'm sorry, but it's true. [2] |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 12:51 PM |
LP = Players.LocalPlayer repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Humanoid") while true do LP.Character.Humanoid.MaxHealth = math.huge wait(5) end --Was it just a health change script? |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
| |
|
|
| 20 Jun 2014 01:03 PM |
| ^^ I don't see you trying -_- |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 01:05 PM |
Color3 uses DECIMAL values, so divide the colors by 255.
Color3.new(150, 0, 0)
Should be
Color3.new(150/255, 0, 0) |
|
|
| Report Abuse |
|
|
jakej78b
|
  |
| Joined: 09 Mar 2011 |
| Total Posts: 813 |
|
|
| 20 Jun 2014 01:05 PM |
| All of you that have just posted a while loop do not know how to code efficiently. I'm sorry, but it's true. [3] Learn to use events, idiots. |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 20 Jun 2014 01:06 PM |
Irrelevant.
Others have provided proper help and you provided nothing useful. |
|
|
| Report Abuse |
|
|
jakej78b
|
  |
| Joined: 09 Mar 2011 |
| Total Posts: 813 |
|
|
| 20 Jun 2014 01:08 PM |
| I love how someone else just used that argument against you but you nullified it by saying they used bad practices now your siding with them, gg bye. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 01:09 PM |
It fun to make things short,cute and to the POINT not a long code. Maybe you guys like it like that. I like make it as short as possible. |
|
|
| Report Abuse |
|
|
Locard
|
  |
| Joined: 13 Apr 2014 |
| Total Posts: 3516 |
|
|
| 20 Jun 2014 01:10 PM |
"Maybe you guys like it like that. I like make it as short as possible."
Short doesn't always mean efficient. I know I wouldn't want to have a while loop when I can just listen for an event instead. |
|
|
| Report Abuse |
|
|