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 » Scripters
Home Search
 

Re: Would this cause unnecessary lag..

Previous Thread :: Next Thread 
C_Sharper is online. 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 is online. 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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
25 Mar 2017 01:03 PM
npc.Humanoid.Touched:Wait()


Report Abuse
C_Sharper is online. 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 is not online. 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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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 is online. 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 is not online. 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 is online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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