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
|
  |
| Joined: 17 Dec 2011 |
| Total Posts: 342 |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 29 Oct 2014 01:27 PM |
| Although it is probably more correct, you do not really need tostring in that context. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 29 Oct 2014 01:34 PM |
I'm sorry about that I meant to start a new thread. |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 03 Nov 2014 05:20 PM |
| Use the Humanoid.HealthChanged(float Health) event |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 03 Nov 2014 05:23 PM |
Do we even need tostring() any more?
**Why should I? Because I can.** |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
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 |
|
|