Geomaster
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1480 |
|
|
| 22 Sep 2013 03:35 AM |
I've got a localscript-based weapon that's very coroutine reliant. However, when more than one are running at once it seems to slow down a bit. I'm probably overlooking a more efficient method, but:
This coroutine is constantly running:
local trans = coroutine.resume(coroutine.create(function() while wait() do for i = 1, 20 do outer.Transparency = outer.Transparency + (.6/20) outerc.Transparency = outer.Transparency + (.6/20) wait(.01) end wait() for i = 1, 20 do outer.Transparency = outer.Transparency - (.6/20) outerc.Transparency = outer.Transparency - (.6/20) wait(.01) end end end))
This coroutine triggers to slowly dissapate the beam whenever the character fires it (mouse):
coroutine.resume(coroutine.create(function() for i = bullet.Transparency, 0, -.1 do bullet.Transparency = 1 - i wait(.01) end game:GetService("Debris"):AddItem(bullet, .2) end)) This one serves the same purpose as before, but for an area-based explosion field:
coroutine.resume(coroutine.create(function() for i = 1, 10 do boom.Transparency = boom.Transparency + (0.6/10) wait(.01) end boom:Destroy() end)) end
This one triggers in the missile firing function to remove it after 8 seconds:
coroutine.wrap(function() wait(8) b:remove() end)
Are there some that I just don't need? Some that I can change around?
|
|
|
| Report Abuse |
|
|
|
| 22 Sep 2013 03:37 AM |
| Yes. instead of remove, do :Destroy() |
|
|
| Report Abuse |
|
|
Geomaster
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1480 |
|
| |
|
|
| 22 Sep 2013 03:40 AM |
| Bleh bleh, never seen so much wait()'s, in one script. Ever. |
|
|
| Report Abuse |
|
|
Geomaster
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1480 |
|
|
| 22 Sep 2013 03:41 AM |
| So, where along the line would that be..helpful? Because I'm picking up: caustic, detrimental, and lazy from that. |
|
|
| Report Abuse |
|
|
|
| 22 Sep 2013 03:44 AM |
Really, I don't use Debris:AddItem(). But it's your choice. Just remove the timeless wait.
local trans = coroutine.resume(coroutine.create(function() while wait() do for i = 1, 20 do outer.Transparency = outer.Transparency + (.6/20) outerc.Transparency = outer.Transparency + (.6/20) wait(.01) end for i = 1, 20 do outer.Transparency = outer.Transparency - (.6/20) outerc.Transparency = outer.Transparency - (.6/20) wait(.01) end end end)) |
|
|
| Report Abuse |
|
|
Geomaster
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1480 |
|
|
| 22 Sep 2013 03:47 AM |
| The beam function actually returns the beam after adding it to debris (there are modifications needed for some things). Calling Destroy on it would give me an error, I'd assume |
|
|
| Report Abuse |
|
|
| |
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 22 Sep 2013 04:28 AM |
Use RunService, not wait()
That should make it lag less. |
|
|
| Report Abuse |
|
|