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: while true do

Previous Thread :: Next Thread 
smunkey is not online. smunkey
Joined: 17 Dec 2011
Total Posts: 342
29 Oct 2014 03:08 AM
I have a fairly simple script that just shows health, but the 'while true do' loop doesn't work. I'm also fairly certain the text is written stupid too. How do I fix it?


local text = script.Parent.Text
local player = game.Players.LocalPlayer
local mhp = player.Humanoid.Maxhealth
local hp = player.Humanoid.Health




While true do
wait ".1"
text = (mhp "/" hp)

end
Report Abuse
smunkey is not online. smunkey
Joined: 17 Dec 2011
Total Posts: 342
29 Oct 2014 03:16 AM
bump :|
Report Abuse
davisky2 is not online. davisky2
Joined: 04 Mar 2012
Total Posts: 4710
29 Oct 2014 04:17 AM
Gawd so many mistakes...

local txt = script.Parent
local player = game.Players.LocalPlayer
local mhp = player.Character.Humanoid.Maxhealth
local hp = player.Character.Humanoid.Health




While true do
wait(.1) -- you can just write 0 or ( ) in there for faster checking...
txt.Text = mhp.."/"..hp

end
Report Abuse
gooey333 is not online. gooey333
Joined: 24 Mar 2013
Total Posts: 1208
29 Oct 2014 09:36 AM
Change your text variable to Text = script.Parent

Change wait".1" to wait(.1)

And change text = (mhp "/" hp) to Text.Text = mhp.."/"..hp
Report Abuse
shadowcrafter80 is not online. shadowcrafter80
Joined: 24 Mar 2013
Total Posts: 1240
29 Oct 2014 11:03 AM
instead of wait "1", do wait(). when you do "1", it doesnt work to it being a string.

You silly bum.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
29 Oct 2014 11:09 AM
Davisky, you could use a good dose of
http://blog.roblox.com/2012/05/using-wait-wisely/
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
29 Oct 2014 12:56 PM
local mhp = game.Players.LocalPlayer.Character..Humanoid.Maxhealth
local hp = game.Players.LocalPlayer.Character.Humanoid.Health

hp.Changed:connect(function(change)
script.Parent.Text = tostring(mhp).." / "..tostring(hp)
end)

mhp.Changed:connect(function(change)
script.Parent.Text = tostring(mhp).. " / "..tostring(hp)
end)
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
29 Oct 2014 01:27 PM
Although it is probably more correct, you do not really need tostring in that context.
Report Abuse
bobbyfishstick5 is not online. bobbyfishstick5
Joined: 24 Oct 2008
Total Posts: 6713
29 Oct 2014 01:31 PM
This script is meant to cause an explosion when the Parent of the script come withing in a certain distance of its intended target.

I already have the distance value taken care of that's not the issue here

It's telling me that I require an end to close the until statement at line 4 I've done that and it still does not resolve the error.

Just need some extra help with this one.


Distval = script.Parent.DistVal.Value
x = Distval <= 50000

if x == nil then wait() until x ~= nil
if x ~= nil then


e = Instance.new("Explosion")
e.Parent = script.Parent
e.Position = script.Parent.Position
e.BlastPressure = 5000
e.BlastRadius = 5000

print"BOOM"

end
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
29 Oct 2014 01:34 PM
I think we've worked out that explosions have no place here XD
Report Abuse
bobbyfishstick5 is not online. bobbyfishstick5
Joined: 24 Oct 2008
Total Posts: 6713
29 Oct 2014 01:34 PM
I'm sorry about that
I meant to start a new thread.
Report Abuse
smunkey is not online. smunkey
Joined: 17 Dec 2011
Total Posts: 342
30 Oct 2014 04:14 PM
Thank you for the help guys

☠I didn't choose the noob life☠
Report Abuse
smunkey is not online. smunkey
Joined: 17 Dec 2011
Total Posts: 342
03 Nov 2014 05:17 PM
The

local txt = script.Parent
local player = game.Players.LocalPlayer
local mhp = player.Character.Humanoid.MaxHealth
local hp = player.Character.Humanoid.Health


while true do
wait(.1)
txt.Text = mhp.."/"..hp

end

script works well enough, but the text doesn't update when the player gets damaged, how do I fix this?
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
03 Nov 2014 05:20 PM
Its because
local mhp = player.Character.Humanoid.MaxHealth --This means mhp is 100
local hp = player.Character.Humanoid.Health --This means hp is 100



while true do
local mhp = player.Character.Humanoid.MaxHealth
local hp = player.Character.Humanoid.Health
wait(.1)
txt.Text = mhp.."/"..hp

end

Now it updates the variables

Or do this


local hum = player.Character.Humanoid

while true do
wait(.1)
txt.Text = hum.MaxHealth.."/"..hum.Health

end



Also PLEASE use the changed event instead of a while loop o3o
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
03 Nov 2014 05:20 PM
Use the Humanoid.HealthChanged(float Health) event
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
03 Nov 2014 05:22 PM
Accessing a property like that is only evaluated once.

local player = game.Players.LocalPlayer;
local humanoid = player.Character.Humanoid;

humanoid.Changed:connect(function ()
script.Parent.Text = humanoid.MaxHealth .. "/" .. humanoid.Health;
end);
Report Abuse
ModDeathRally9 is not online. ModDeathRally9
Joined: 02 Sep 2012
Total Posts: 370
03 Nov 2014 05:23 PM
Do we even need tostring() any more?

**Why should I? Because I can.**
Report Abuse
AdorableFerretsRus is not online. AdorableFerretsRus
Joined: 27 May 2012
Total Posts: 3903
03 Nov 2014 05:24 PM
Change

wait".1"

to one of the following:

wait(0.1)

OR

wait(.1)

OR

wait(1/10)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
03 Nov 2014 05:28 PM
Adorable, it doesn't matter.
Roblox is nice enough to convert it into a number for us
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
03 Nov 2014 05:29 PM
Lua* is nice enough to do the implicit typecasting automatically.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
03 Nov 2014 05:33 PM
That might not be true, depending on how Roblox handles threads.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
03 Nov 2014 05:34 PM
It's Lua that does the implicit typecasting for us.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
03 Nov 2014 05:35 PM
But there is no typecasting done here by Lua.
sleep is roblox-specific, and if they call a c-function which does not convert it, then that
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
03 Nov 2014 05:35 PM
wait*
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
03 Nov 2014 05:38 PM
... You're right, my bad. I was thinking Lua in general. Unless it was implemented in pure Lua.
In general, it doesn't matter because Lua does most implicit typecasting.
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