|
| 16 Sep 2012 05:24 PM |
Hi, me and my friend have been working on a script for a new upcoming game, but it isn't working right.
What he script does is it adds 30 health points without going over 100, if it does it is brought down to 100.
Here is the script;
game.Workspace.MedicalPresent.Handle.Touched:connect(function(hit) local h = hit.Parent:FindFirstChild("Humanoid") if h == nil then return end if h.Health < h.MaxHealth then h.Health = (h.Health + 30) if h.Health > 100 then h.Health=100 end Workspace.MedicalPresent:remove() end end)
There are no output errors, it works normal except it goes over 100 if I have more than 60 health points when using the present. I do not want it to go over 100. Help?
|
|
|
| Report Abuse |
|
|
| |
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 16 Sep 2012 06:21 PM |
| If you touch it multiple times (which almost always happens when you step on something, for instance), it may heal you more than once and then be removed by the first runthrough of the script before the second one finishes. |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 06:27 PM |
local Touched = false Game.Workspace.MedicalPresent.Handle.Touched:connect(function(hit) local h = hit.Parent:FindFirstChild("Humanoid") if not h or Touched then return end Touched = true if h.Health < h.MaxHealth and not ((h.Health + 30) >= h.MaxHealth) then h.Health = (h.Health + 30) else h.Health = h.MaxHealth end Workspace.MedicalPresent:Destroy() Touched = false end)
¤ ¤ † K M X D † ¤ ¤ |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 07:02 PM |
@solotare
ya, but the script says it cannot go over 100 even if it adds 30 extra. else it's brought back down to 100 |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 07:07 PM |
Did you try my script?
¤ ¤ † K M X D † ¤ ¤ |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 07:07 PM |
It won't go over 100 anyway, not unless you change the MaxHealth value in the player to over 100.
-- I'm not a Wizard. I'm THE Wizard -- |
|
|
| Report Abuse |
|
|