Makumio
|
  |
| Joined: 10 Aug 2012 |
| Total Posts: 54 |
|
|
| 14 Sep 2016 06:11 AM |
How would I loop a damage script whilst the enemy is inside the brick which is the hitbox.
I have this script but it is not very efficient because if you stop moving the damage will stop as well. Is it possible to loop the damage whilst touching the brick and stop till the player stops touching the brick.
function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil) then human.Health = human.Health - 0.5 end end
script.Parent.Touched:connect(onTouched)
Thanks
Makumio |
|
|
| Report Abuse |
|
|
|
| 14 Sep 2016 06:14 AM |
While true do if human ~= nil then hum.Health = hum.Health - .5
http://wiki.roblox.com/?title=Loops |
|
|
| Report Abuse |
|
|
WoolHat
|
  |
| Joined: 19 May 2013 |
| Total Posts: 1873 |
|
|
| 14 Sep 2016 07:41 AM |
https://forum.roblox.com/Forum/ShowPost.aspx?PostID=198280060
The first one is more efficient, so to speak. I plan on improving it by passing a function as a variable, but until then, that's a good bet. You'll have to manipulate some of the code (like "torso" being the only valid touching part. I did that so the script doesn't run double when a player steps on it with both feet. |
|
|
| Report Abuse |
|
|
|
| 14 Sep 2016 07:51 AM |
local d = false
script.Parent.Touched:connect(function(p) if p.Parent.Humanoid then d = true while d do p.Parent.Humanoid.Health = p.Parent.Humanoid.Health - 10 wait(1) end end end)
script.Parent.TouchEnded:connect(function(p) if p.Parent.Humanoid then d = false end end) |
|
|
| Report Abuse |
|
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
|
| 14 Sep 2016 07:59 AM |
^ @Above Post
Didn't even know TouchEnded Existed, that's a helpful little thing! Thanks for that actually.
|
|
|
| Report Abuse |
|
|
Mitko0o1
|
  |
| Joined: 30 Nov 2010 |
| Total Posts: 5725 |
|
|
| 14 Sep 2016 08:08 AM |
| ############################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################## |
|
|
| Report Abuse |
|
|
Mitko0o1
|
  |
| Joined: 30 Nov 2010 |
| Total Posts: 5725 |
|
|
| 14 Sep 2016 08:08 AM |
| wow these hashtags, i give up |
|
|
| Report Abuse |
|
|
| |
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
|
| 14 Sep 2016 08:11 AM |
Forum doesn't like pastebin and hashtags it too :L
|
|
|
| Report Abuse |
|
|
Mitko0o1
|
  |
| Joined: 30 Nov 2010 |
| Total Posts: 5725 |
|
| |
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
|
| 14 Sep 2016 08:15 AM |
*claps* I stand corrected, I guess the forum just hates me then, lol.
|
|
|
| Report Abuse |
|
|
Makumio
|
  |
| Joined: 10 Aug 2012 |
| Total Posts: 54 |
|
|
| 14 Sep 2016 08:22 AM |
Thanks everyone this has helped me and finally mobs have a working hitbox that can no longer be avoided by trapping them on other objects.
Thanks a bunch
Makumio |
|
|
| Report Abuse |
|
|