| A Nice Health Pad | |
|
|
Author | Message |
---|
Guest Guest
| Subject: A Nice Health Pad August 3rd 2010, 2:54 pm | |
| - Code:
-
local heal = 20 --How much it heals local waiting = 2 --How long before can be used again
local debo = false
function onTouch(hit) if hit.Parent.Humanoid ~= nil and debo == false then debo = true hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health + heal --script.Parent:Remove() --Remove the '--' at the start of the line for one use only wait(waiting) debo = false end end
script.Parent.Touched:connect(onTouch) |
|
| |
Guest Guest
| Subject: Re: A Nice Health Pad August 8th 2010, 10:04 pm | |
| |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: A Nice Health Pad August 10th 2010, 12:19 am | |
| | |
|
| |
Guest Guest
| Subject: Re: A Nice Health Pad August 10th 2010, 3:19 pm | |
| But, he added a script to the resources. I never really look at the script anyways xD Let's make it more efficent, though. - Code:
-
script.Parent.Touched:connect(function(hit) wait() hit.Parent.Humanoid:takeDamage(-20) script.Parent:Remove() end) |
|
| |
Guest Guest
| Subject: Re: A Nice Health Pad November 29th 2010, 4:21 pm | |
| Its all very good, but what if I program a brick to go over the pad containing the script, it will brake. Just at this into the script to make it a little better. local hum = hit.Parent:findFirstChild("Humanoid") if hum~=nil then [Builderboy202] |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: A Nice Health Pad December 15th 2010, 6:38 pm | |
| - Code:
-
script.Parent.Touched:connect(function(hit) wait() if hit.Parent:findFirstChild("Humanoid") then hit.Parent.Humanoid:takeDamage(-20) script.Parent:Remove() end end
| |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: A Nice Health Pad January 18th 2011, 10:19 pm | |
| - Code:
-
script.Parent.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") then hit.Parent.Humanoid:takeDamage(-20) script.Parent:Remove() end end forgot to put ) at the end of the function and why do you need a wait() for? its blank | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: A Nice Health Pad January 18th 2011, 10:19 pm | |
| - Code:
-
script.Parent.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") then hit.Parent.Humanoid:takeDamage(-20) script.Parent:Remove() end end) ugh | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: A Nice Health Pad January 18th 2011, 10:21 pm | |
| Sometimes roblox would glitch this. A better way to prevent that would be to add debounce. | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: A Nice Health Pad January 18th 2011, 11:54 pm | |
| - Code:
-
script.Parent.Touched:connect(function(hit) local deb = false if deb = false then deb = true if hit.Parent:findFirstChild("Humanoid") then hit.Parent.Humanoid:takeDamage(-20) script.Parent:Remove() end deb = false end) i dont know why you would need it in this case anyway, your heal pad would just be removed | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: A Nice Health Pad January 19th 2011, 7:55 pm | |
| Ah. didn't see that. But you broke the script BTW ;) - Code:
-
if deb == true then You need two ='s. | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: A Nice Health Pad January 19th 2011, 8:56 pm | |
| nooooo. oh well. we all make mistakes. | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: A Nice Health Pad January 19th 2011, 8:58 pm | |
| - Code:
-
script.Parent.Touched:connect(function(hit) local deb = false if deb == false then deb == true if hit.Parent:findFirstChild("Humanoid") then hit.Parent.Humanoid:takeDamage(-20) end wait(60) deb = false end) i removed :Remove(), debounce would be useless if this wasn't done. also added wait(60) that's better. i think. | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: A Nice Health Pad January 19th 2011, 9:56 pm | |
| Last I remember, local isn't needed in RBX.lua. | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: A Nice Health Pad January 19th 2011, 10:42 pm | |
| ah... but this time i have a trick. local is used for optimization (enhancing speed), it is said in lua that you should use local variables as much as possible. it saves more memory usage than using global variables. proof is in the simple script of the widely-used LinkedSword, first made by the admins of roblox. they know more about optimization than me. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: A Nice Health Pad January 20th 2011, 6:58 pm | |
| Code: script.Parent.Touched:connect(function(hit) pcall(hit.Parent.Humanoid:takeDamage(-20) script.Parent:Remove()) end)
| |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: A Nice Health Pad January 20th 2011, 7:50 pm | |
| Well, local doesn't determine a variables *** in RBX.lua for some reason. They removed it apparently. | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: A Nice Health Pad January 20th 2011, 9:12 pm | |
| say again? oh and what is pcall() | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: A Nice Health Pad January 21st 2011, 3:16 am | |
| pcall runs a function in protected mode so it won't crash the script if there is an error in the function. | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: A Nice Health Pad January 27th 2011, 10:32 pm | |
| how does it work? and does it limit the flexibility of the script? | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: A Nice Health Pad January 29th 2011, 7:49 am | |
| you can not use waits in pcall or xpcall. | |
|
| |
lukenuke75 Novice Scripter
Posts : 38 Join date : 2011-03-07 Age : 27
| Subject: Re: A Nice Health Pad March 9th 2011, 12:15 am | |
| wait() is not blank silly :D
its 0.035009250178941
NOTE: i did not know there was a second page :P | |
|
| |
MrNicNac Expert Scripter
Posts : 27 Join date : 2011-03-06 Age : 28
| Subject: Re: A Nice Health Pad March 10th 2011, 10:12 am | |
| - naknak wrote:
- Last I remember, local isn't needed in RBX.lua.
It doesn't matter if it is RBX.Lua or Lua, local can be needed. If not needed, it is suggested. Local variables integrate themselves into the environment, making indexing them much faster. | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: A Nice Health Pad March 10th 2011, 11:32 pm | |
| More typing = faster script
Confusing, much? Oh well, I'll start using local's again and see if I see a difference. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: A Nice Health Pad March 11th 2011, 8:35 pm | |
| oysi ran a test and said that local variables were vaster than normal. ever since i've used local variables many times. XD
| |
|
| |
Sponsored content
| Subject: Re: A Nice Health Pad | |
| |
|
| |
| A Nice Health Pad | |
|