C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 25 Mar 2017 12:59 PM |
I have attack functions in a table in each of the npc keys in my dictionary NPC module.
So say I have this:
attacks = {
function(npc) --the npc is passed through the script requiring the module local t = npc.Torso.Touched:connect(function(hit)
end) wait(2) t:disconnect() end; }
Would this, slow down the game, or is there a better way to do this. I want to play an animation of the NPC and then take damage if a body part of theirs is touched. Since some NPC's do not require a part of their body touching to deal damage, I figured I could include the touched event inside of the attack function, and I'd use spawn() from the calling script so it wouldn't yield that thread.
Just how efficient is this? Could this slow down my game noticeably? I need expert advice here, and if it would slow it down a good chunk, please recommend a new method of doing this. Thanks! |
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 25 Mar 2017 01:02 PM |
And to be honest, I don't even know if a disconnect() is necessary here. Because the function ends after 2 seconds, would the event I attached to a function [touched] be popped off the stack, therefor not functioning any longer?
Not entirely sure. |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2017 01:03 PM |
npc.Humanoid.Touched:Wait()
|
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 25 Mar 2017 01:06 PM |
Well, I assume that yields until something hits the humanoid. However, I want there to be a maximum waiting time of 2 seconds, and then the function ends.
Thanks though |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 25 Mar 2017 01:07 PM |
| You really shouldn't be worrying about optimization until you have the whole picture done. And no, this shouldn't. And Yes, you need to disconnect() the event. |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2017 01:07 PM |
Oh I didn't understand your post The way you're doing it is fine
|
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 25 Mar 2017 01:14 PM |
Aye thanks guys. I'm just concerned about making this the best it can be.
And ok, I will disconnect it. Just thought maybe it popped off the stack when the function finished running. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 25 Mar 2017 01:19 PM |
(function() workspace.Baseplate.Touched:connect(workspace.Baseplate.BreakJoints) end)() --// the floor is lava --// notice how the event persists even though the function has long since ended. |
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 25 Mar 2017 01:23 PM |
Well, you learn something new every day.
Thanks for the info. |
|
|
| Report Abuse |
|
|