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: Working on a script to change some values

Previous Thread :: Next Thread 
SundownMKII is not online. SundownMKII
Joined: 26 Sep 2010
Total Posts: 12880
12 Nov 2011 05:55 AM
and I'm not sure it'll execute.
Attempting to get the value to change accordingly with a Humanoid's Health value and react to damage by changing the Color3 of the TextLabel if it drops below a certain value.

Script:


HP = script.Parent.Parent.Parent.Parent:findFirstChild("Humanoid").Health

while true do
HP = script.Parent.Text
if HP > 25 then -- if it's bigger than 25 then
script.Parent.TextColor3 = Color3.new(0, 255, 0) -- character is fine, label is green
elseif HP =< 25 then -- if it's equal to or smaller than 25 then
script.Parent.TextColor3 = Color3.new(255, 0, 0) -- character is hurt, label is red
wait(0.1)
end
end
Report Abuse
1xCCx1 is not online. 1xCCx1
Joined: 07 Nov 2011
Total Posts: 20
12 Nov 2011 06:03 AM
I don't have much experience with LUA, but if it's anything like PHP, then it seems you are setting the HP variable at the start of the script, and then resetting it on each runthrough of the while!

1xC
Report Abuse
SundownMKII is not online. SundownMKII
Joined: 26 Sep 2010
Total Posts: 12880
12 Nov 2011 06:05 AM
Let me explain a bit more:

Here's the humanoid, and let's say it has 100 HP.
Now, we strike it with something, and it drops down to 75 HP.
I'm trying to get the BillboardGUI to update every tenth of a second with the humanoid's health so I don't have to continually look in Studio to find out what the damage was.
Report Abuse
1xCCx1 is not online. 1xCCx1
Joined: 07 Nov 2011
Total Posts: 20
12 Nov 2011 06:13 AM
I know that,
But what you are doing is setting the first HP to the correct value, then CHANGING it on each runthrough of the while!
Wait, let me rewrite that,

1xC
Report Abuse
1xCCx1 is not online. 1xCCx1
Joined: 07 Nov 2011
Total Posts: 20
12 Nov 2011 06:14 AM
Script:
HP = game.Workspace:findFirstChild("Humanoid").Health
while true do
if HP ​> 25 then -- if it's bigger than 25 then
script.Parent.TextColor3 = Color3.new(0, 255, 0) -- character is fine, label is green
elseif HP =< 25 then -- if it's equal to or smaller than 25 then
script.Parent.TextColor3 = Color3.new(255, 0, 0) -- character is hurt, label is red
wait(0.1)
end
end

1xC
Report Abuse
RandyOrton0068 is not online. RandyOrton0068
Joined: 27 Jul 2011
Total Posts: 5580
12 Nov 2011 06:14 AM
@1xccx1: I disagree in my opinion.
Report Abuse
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
12 Nov 2011 06:15 AM
Like 1xC said, you are resetting it each time.

~ ~ ~ I have your soul, in my bag.
Report Abuse
SundownMKII is not online. SundownMKII
Joined: 26 Sep 2010
Total Posts: 12880
12 Nov 2011 06:15 AM
Yeah, but I was trying to change the value of the text to be the same as the humanoid's HP.
Report Abuse
RandyOrton0068 is not online. RandyOrton0068
Joined: 27 Jul 2011
Total Posts: 5580
12 Nov 2011 06:16 AM
@SoulStealer9875: Agreed.
Report Abuse
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
12 Nov 2011 06:17 AM
I know, but why are you making the same variable twice with two different meanings?


~ ~ ~ I have your soul, in my bag.
Report Abuse
RandyOrton0068 is not online. RandyOrton0068
Joined: 27 Jul 2011
Total Posts: 5580
12 Nov 2011 06:18 AM
Lol.
Report Abuse
SundownMKII is not online. SundownMKII
Joined: 26 Sep 2010
Total Posts: 12880
12 Nov 2011 06:22 AM
That's a fail on my part.

I'm trying to work on getting the value (Humanoid.Health) to become the text (TextLabel.Text). I thought that would work.
Report Abuse
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
12 Nov 2011 06:30 AM
Try this:

HP = script.Parent.Parent.Parent.Parent:findFirstChild("Humanoid")
while true do
HP.Health = script.Parent.Text
if HP.Health ​> 25 then -- if it's bigger than 25 then
script.Parent.TextColor3 = Color3.new(0, 255, 0) -- character is fine, label is green
elseif HP.Health =< 25 then -- if it's equal to or smaller than 25 then
script.Parent.TextColor3 = Color3.new(255, 0, 0) -- character is hurt, label is red
wait(0.1)
end
end
Report Abuse
SundownMKII is not online. SundownMKII
Joined: 26 Sep 2010
Total Posts: 12880
12 Nov 2011 06:43 AM
Returns this:

Sat Nov 12 07:41:52 2011 - Running Script "Workspace.Noob.Head.BillboardGui.Name.Script"
Sat Nov 12 07:41:52 2011 - Workspace.Noob.Head.BillboardGui.Name.Script:4: 'then' expected near '?'
Report Abuse
therealergo is not online. therealergo
Joined: 27 Sep 2009
Total Posts: 248
12 Nov 2011 07:25 AM
HP = script.Parent.Parent.Parent.Parent:findFirstChild("Humanoid")
while true do
HP.Health = script.Parent.Text
if HP.Health>25 then
script.Parent.TextColor3 = Color3.new(0, 255, 0)
elseif HP.Health=<25 then
script.Parent.TextColor3 = Color3.new(255, 0, 0)
wait(0.1)
end
end

that might work... Lua is sometimes annoying like that for me.
Report Abuse
therealergo is not online. therealergo
Joined: 27 Sep 2009
Total Posts: 248
12 Nov 2011 07:26 AM
HP = script.Parent.Parent.Parent.Parent:findFirstChild("Humanoid")
while true do
HP.Health = script.Parent.Text
if HP.Health>25 then
script.Parent.TextColor3 = Color3.new(0, 255, 0)
elseif HP.Health=<25 then
script.Parent.TextColor3 = Color3.new(255, 0, 0)
end
wait(0.1)
end

sorry for double post, but you dont want to crash your game :0
Report Abuse
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
12 Nov 2011 07:28 AM
@ther, that won't crash the game it's got a wait in it.
Report Abuse
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
12 Nov 2011 07:29 AM
Try this:

HP = script.Parent.Parent.Parent.Parent:findFirstChild("Humanoid")
while true do
HP.Health = tonumber(script.Parent.Text)
if HP.Health ​> 25 then
script.Parent.TextColor3 = Color3.new(0, 255, 0)
elseif HP.Health <= 25 then
script.Parent.TextColor3 = Color3.new(255, 0, 0)
wait(0.1)
end
end
Report Abuse
therealergo is not online. therealergo
Joined: 27 Sep 2009
Total Posts: 248
12 Nov 2011 07:44 AM
HP = script.Parent.Parent.Parent.Parent:findFirstChild("Humanoid")

    while true do
        HP.Health = tonumber(script.Parent.Text)
        if HP.Health ​> 25 then
            script.Parent.TextColor3 = Color3.new(0, 255, 0)
        elseif HP.Health <= 25 then
            script.Parent.TextColor3 = Color3.new(255, 0, 0)
            wait(0.1)
        end
    end

look at where that wait is placed - it will only wait if HP.Health <= 25, so it will crash your game if HP.Health ​> 25

    while true do
        HP.Health = tonumber(script.Parent.Text)
        if HP.Health​>25 then
            script.Parent.TextColor3 = Color3.new(0, 255, 0)
        elseif HP.Health<=25 then
            script.Parent.TextColor3 = Color3.new(255, 0, 0)
        end
        wait(0.1)
    end
Report Abuse
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
12 Nov 2011 08:06 AM
Oh yeah, good catch.
Report Abuse
RandyOrton0068 is not online. RandyOrton0068
Joined: 27 Jul 2011
Total Posts: 5580
13 Nov 2011 10:45 AM
@SoulStealer9875: Yeah.
Report Abuse
SundownMKII is not online. SundownMKII
Joined: 26 Sep 2010
Total Posts: 12880
13 Nov 2011 01:31 PM
Ok, it works, but the colors are off.
I think I need to convert them to the 1 = 255 RGB scale.
Report Abuse
LordStriked is not online. LordStriked
Joined: 19 Mar 2011
Total Posts: 5396
13 Nov 2011 01:37 PM
changing color 3, it has to be divided by 255

if it's gree (0/255, 255/255, 0/255)
Report Abuse
LordStriked is not online. LordStriked
Joined: 19 Mar 2011
Total Posts: 5396
13 Nov 2011 01:37 PM
green*
Report Abuse
SundownMKII is not online. SundownMKII
Joined: 26 Sep 2010
Total Posts: 12880
13 Nov 2011 01:40 PM
I had fixed that because of the Wiki ( gotta love them color3 things ).

Thanks for the help!
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