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: Health Giver

Previous Thread :: Next Thread 
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
29 Nov 2013 08:08 PM
I am making a war game. I am trying to make health packs. I need a brick on collision to add X amount of health to the player, however, it can only be used one every minute. I have got it to add health, I just can't get it to disappear for a minute. Here is my script:

function onTouched(hit)
if hit.Parent.Humanoid.Parent ~= nil then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health+10
end
end
script.Parent.Touched:connect(onTouched)

Can anyone add the part that makes if invisible and unusable for a minute? Thanks!
Report Abuse
robomax11 is not online. robomax11
Joined: 07 Jul 2011
Total Posts: 6828
29 Nov 2013 08:10 PM
yolo = true

function onTouched(hit)
if hit.Parent.Humanoid.Parent ~= nil and yolo == true then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health+10
end
end
yolo = false
script.Parent.Transparency = 1
wait(60)
yolo = true
script.Parent.Transparency = 0
script.Parent.Touched:connect(onTouched)
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
29 Nov 2013 08:11 PM
lasthit=false
function onTouched(hit)
if hit.Parent.Humanoid.Parent ~= nil and not lasthit then lasthit=true
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health+10
script.Parent.Transparency=1
wait(60) lasthit=false
end
end
script.Parent.Touched:connect(onTouched)
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
29 Nov 2013 08:12 PM
Sniped.
And he did better because he made it visible again.
Use his.
Report Abuse
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
29 Nov 2013 08:51 PM
Thanks for what you guys did! However, I seemed to have incorrectly stated what I was trying to get the button to do. I am trying to get it to disappear after each use for one minute before it becomes usable again. The script you supplied (which was very generous of you) rendered the button unusable for only the first minute of the game starting. Sorry for the misunderstanding!
Report Abuse
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
29 Nov 2013 09:49 PM
Anyone?
Report Abuse
drew8732 is not online. drew8732
Joined: 01 Apr 2010
Total Posts: 1965
29 Nov 2013 10:18 PM
This is a method called "debounce," the wiki will proabably do a better job explaining than me.

http://wiki.roblox.com/index.php/Debounce

You can add this method in to any script with 4 extra lines, here's the basic format:

local debounce = false -- Define a false variable at top of script

function OnTouch(blah)
if not debounce then -- Conditional statement after touched function, if it's been used it won't fire
debounce = true -- Set variable on, so if used within inactivity, the function won't fire
[Insert heal code here]
wait(cooldown)
debounce = false -- Make it false once more so the tool is ready to be used
end

blah.Touched:connect()

Be sure to check out the wiki, that will give you a better explanation.



Report Abuse
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
30 Nov 2013 08:18 AM
Okay. But is this right?


local debounce = false -- Define a false variable at top of script

function OnTouch(blah)
if not debounce then -- Conditional statement after touched function, if it's been used it won't fire
debounce = true -- Set variable on, so if used within inactivity, the function won't fire

function onTouched(hit)
if hit.Parent.Humanoid.Parent ~= nil then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health+10
end
end
script.Parent.Touched:connect(onTouched)

wait(cooldown)
debounce = false -- Make it false once more so the tool is ready to be used
end

blah.Touched:connect()
Report Abuse
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
30 Nov 2013 08:42 AM
is it?
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
30 Nov 2013 08:59 AM
you have to find the humanoid
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
30 Nov 2013 09:01 AM
use this.

H = 5 --health amount added per hit on the object here

function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
wait(.01)
human.Health = human.Health + H
wait(.01)
end
end

script.Parent.Touched:connect(onTouched)
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
30 Nov 2013 09:04 AM
oh once, then use this:
H = 10 --Health amount here

local players = { }
local debounce = false

script.Parent.Touched:connect(function(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (not debounce) then
if (human) and (not players[player.Name]) then
debounce = true
if (human ~= nil) then
wait(.01)
human.Health = human.Health + H
wait(.01)
debounce = false
end
end
end)

tell me if this works
Report Abuse
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
30 Nov 2013 09:38 AM
Well, the first one adds health, but doesn't destroy it's self. The second just doesn't work.
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
30 Nov 2013 09:44 AM
oh destroy?
here:
H = 5 --health amount added per hit on the object here

function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
wait(.01)
human.Health = human.Health + H
script.Parent:remove
wait(.01)
end
end

script.Parent.Touched:connect(onTouched)

try that
Report Abuse
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
30 Nov 2013 10:16 AM
function arguments near "wait"
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
30 Nov 2013 11:26 AM
H = 5 --health amount added per hit on the object here

function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
wait(.01)
human.Health = human.Health + H
script.Parent:remove()
wait(.01)
end
end

script.Parent.Touched:connect(onTouched)


oops tiny mistake
here you go
Report Abuse
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
30 Nov 2013 10:14 PM
Thanks! It works! Very Happy! Though, can you make it so that it doesn't add health past the max amount? I set it to 50 so it would give you half health back, but I don't want it to add health exceeding the normal health ammount, just get it back up to 100, not past. Thanks!
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
30 Nov 2013 10:41 PM
what?
cant understand what you want...
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
30 Nov 2013 11:19 PM
http://web.roblox.com/Solution-item?id=11419319
Report Abuse
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
01 Dec 2013 11:39 AM
I need like a brick that isn't an item. Just as a med pack you find and can get. The problem is, I don't want it to add health past the normal level.

example:
I lose 5 health and touch the pack, the health pack is adding 50 health. so it turns my health into 145. I only want it to add health up to 100 and stop.
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
01 Dec 2013 04:10 PM
H = 5 --health amount added per hit on the object here

function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
if human.Health > 50 then
wait(0.1)
human.Health = 100
else
wait(.01)
human.Health = human.Health + H
script.Parent:remove()
end
end
end

script.Parent.Touched:connect(onTouched)

try that
i seem not to have luck with else so try it
Report Abuse
brickzombie is not online. brickzombie
Joined: 18 Jan 2012
Total Posts: 260
03 Dec 2013 06:31 AM
It work GREAT! Thank you SO MUCH! The only thing is, for some reason, it doesn't delete after adding the health...
Report Abuse
Predator205660 is not online. Predator205660
Joined: 26 Jul 2011
Total Posts: 3757
03 Dec 2013 07:22 AM
":remove()"

I think it should be ":Remove()"
I'm pretty sure it's case sensitive.
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
03 Dec 2013 07:43 AM
A bit of an experiment.

local disconnect = true

script.Parent.Touched:connect(function(p)
pcall(disconnect and (function()
disconnect = false
p.Parent.Humanoid.Health = p.Parent.Humanoid.Health + 10
wait(60)
disconnect = true
end) or function() end)
end)
Report Abuse
2tabbycat is not online. 2tabbycat
Joined: 07 Sep 2010
Total Posts: 1692
03 Dec 2013 09:32 AM
Debounce should be false, Correct?
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