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 » Scripting Helpers
Home Search
 

Re: Health GUI Help

Previous Thread :: Next Thread 
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:20 PM
So. I have made a health GUI. I am sure that I have the local script right:

LocalScript:

wait(0.5)
game.StarterGui:SetCoreGuiEnabled("Health",false)

But I am not sure about the HP script…Nothing in the output window. I have no idea what I am doing wrong.

HP Script:

local char = script.Parent.Parent.Parent.Character
hum = char.Humanoid
hum.Changed:Connect(function()
script.Parent.Frame.Health.Frame.Size = UDim2.new(hum.Health/hum.MaxHealth,0,1,0)
script.Parent.Frame.Text.TextLabel.Text = "..hum.Health.."/"..hum.MaxHealth.."
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,170,0)
end
end)
Report Abuse
WishNite is not online. WishNite
Joined: 11 Feb 2009
Total Posts: 15828
13 Jul 2014 12:22 PM
i assume its because the character isnt "loaded" when the script is run
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:23 PM
So how do I fix that? By the way, the only thing related to the HP script is something in line 3?
Report Abuse
warriorqaz is not online. warriorqaz
Joined: 09 Oct 2009
Total Posts: 726
13 Jul 2014 12:27 PM
I would take out wait(.5) at the top and put this in:

repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Torso")

Waiting .5 might not be long enough. This will make the wait exactly as long as you need it to be.
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:32 PM
Did nothing. If it makes any difference, this is what the local script says now:

repeat wait() until game.Players.LocalPlayer and
game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Torso")
game.StarterGui:SetCoreGuiEnabled("Health",false)
Report Abuse
warriorqaz is not online. warriorqaz
Joined: 09 Oct 2009
Total Posts: 726
13 Jul 2014 12:33 PM
I believe I figured it out. The think problem is in this line:

script.Parent.Frame.Text.TextLabel.Text = "..hum.Health.."/"..hum.MaxHealth.."

You can't divide a string value by a string value. Try this:

script.Parent.Frame.Text.TextLabel.Text = hum.Health.."/"..hum.MaxHealth
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:36 PM
Still nothing. Like I said though. There is blue lettering that says something about line 3? in the hp script.
Report Abuse
warriorqaz is not online. warriorqaz
Joined: 09 Oct 2009
Total Posts: 726
13 Jul 2014 12:37 PM
Paste line 3, please.
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:37 PM
hum.Changed:Connect(function()
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:38 PM
In response to the string value thing where you thought that was the line that was screwed up, don't you need to have quotations at either end?
Report Abuse
warriorqaz is not online. warriorqaz
Joined: 09 Oct 2009
Total Posts: 726
13 Jul 2014 12:39 PM
I think it's because you have to say

hum.Health.Changed:Connect(function()
Report Abuse
warriorqaz is not online. warriorqaz
Joined: 09 Oct 2009
Total Posts: 726
13 Jul 2014 12:42 PM
Nevermind, Changed is part of Humanoid. I have no idea what the problem is.

About the string values, any time you put quotes around something, it becomes a string. It doesn't matter what's inside the quotes.
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:43 PM
Nol That gave me this red output:

20:41:28.917 - Players.Player1.PlayerGui.Health.HP:3: attempt to index field 'Health' (a number value)

SO I need to switch back to what I had before
Report Abuse
warriorqaz is not online. warriorqaz
Joined: 09 Oct 2009
Total Posts: 726
13 Jul 2014 12:48 PM
After doing a little messing around with functions, I MAY have debunked the mystery. I made a simple click gui and found that it didn't work when "connect" had an uppercase C and there was nothing in the output. This could be your problem.
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:48 PM
Where do I change connect?
Report Abuse
warriorqaz is not online. warriorqaz
Joined: 09 Oct 2009
Total Posts: 726
13 Jul 2014 12:50 PM
hum.Changed:Connect(function()
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:51 PM
I just did. Still nothing. here is what I have now:

Local:

repeat wait() until game.Players.LocalPlayer and
game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Torso")
game.StarterGui:SetCoreGuiEnabled("Health",false)

and HP:

local char = script.Parent.Parent.Parent.Character
hum = char.Humanoid
hum.Changed:connect(function()
script.Parent.Frame.Health.Frame.Size = UDim2.new(hum.Health/hum.MaxHealth,0,1,0)
script.Parent.Frame.Text.TextLabel.Text = hum.Health.."/"..hum.MaxHealth
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,170,0)
end
end)
Report Abuse
warriorqaz is not online. warriorqaz
Joined: 09 Oct 2009
Total Posts: 726
13 Jul 2014 12:55 PM
When things that I make break, I add prints everywhere to see where it stops breaking. Try that.
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:56 PM
Where should i add the prints?
Report Abuse
warriorqaz is not online. warriorqaz
Joined: 09 Oct 2009
Total Posts: 726
13 Jul 2014 12:57 PM
Before you take my poor advice (clearly I'm not an expert), what exactly isn't happening?
Report Abuse
Cheeso135 is not online. Cheeso135
Joined: 13 Apr 2013
Total Posts: 2016
13 Jul 2014 12:58 PM
The health bar is not changing. It should, but it is not moving when I change health.
Report Abuse
tarrdo is not online. tarrdo
Joined: 24 Jun 2008
Total Posts: 476
13 Jul 2014 12:59 PM
repeat wait() until game.Players.LocalPlayer and
game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Humanoid") -- Humanoid holds HP so if it's supposed to scan for Health this is what you need
game.StarterGui:SetCoreGuiEnabled("Health",false)



local char = script.Parent.Parent.Parent.Character
hum = char.Humanoid
hum.Changed:connect(function()
script.Parent.Frame.Health.Frame.Size = UDim2.new(hum.Health/hum.MaxHealth,0,1,0)
script.Parent.Frame.Text.TextLabel.Text = hum.Health.."/"..hum.MaxHealth
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,170,0)
end
end)
Report Abuse
tarrdo is not online. tarrdo
Joined: 24 Jun 2008
Total Posts: 476
13 Jul 2014 01:02 PM
and for prints I would do

repeat wait() until game.Players.LocalPlayer and
game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Humanoid")
game.StarterGui:SetCoreGuiEnabled("Health",false)

and HP:

local char = script.Parent.Parent.Parent.Character
hum = char.Humanoid
hum.Changed:connect(function()
print("Connected")
script.Parent.Frame.Health.Frame.Size = UDim2.new(hum.Health/hum.MaxHealth,0,1,0)
script.Parent.Frame.Text.TextLabel.Text = hum.Health.."/"..hum.MaxHealth
if hum.Health <= hum.MaxHealth*0.15 then
Print("Am I Working Here")
script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new (150,0,0)
else
script.Parent.Frame.Health.Frame.BackgroundColor3 = Color3.new (0,170,0)
end
end)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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