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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Why won't my Medical present script work properly?

Previous Thread :: Next Thread 
cornholio234 is not online. cornholio234
Joined: 22 Oct 2010
Total Posts: 15142
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
cornholio234 is not online. cornholio234
Joined: 22 Oct 2010
Total Posts: 15142
16 Sep 2012 06:18 PM
bump
Report Abuse
Solotaire is not online. 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
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
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
cornholio234 is not online. cornholio234
Joined: 22 Oct 2010
Total Posts: 15142
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
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
16 Sep 2012 07:07 PM
Did you try my script?

¤ ¤ † K M X D † ¤ ¤
Report Abuse
Wizard2268 is not online. Wizard2268
Joined: 31 Mar 2011
Total Posts: 985
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
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