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: Cannot resume a dead coroutine

Previous Thread :: Next Thread 
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
01 Sep 2016 04:28 PM
I'm trying to detect every part in the Workspace named "PlateLevi", and set them moving asynchronously. However, when there exists more than 1 part with the name PlateLevi in Workspace, the script returns an error, telling me that I cannot resume a dead coroutine. Any ideas on how I can work around this?

math.randomseed(tick())

local Levitate
Levitate = coroutine.wrap(function(Brick)
while wait() do
local Origin = Brick.CFrame
Brick.CFrame = Origin*CFrame.new(0,math.sin(tick()),0)
end
end)

for i,v in pairs(workspace:GetChildren()) do
if v.Name == "PlateLevi" then
Levitate(v)
wait(math.random(1,10)/10)
end
end

Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
01 Sep 2016 04:29 PM
The Origin variable is also outside of the while wait() do, that's fixed in the real script.
Report Abuse
Monadic is not online. Monadic
Joined: 03 Aug 2016
Total Posts: 731
01 Sep 2016 04:29 PM
Trying to bring back things from the dead I see...
smh
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
01 Sep 2016 04:31 PM
most efficient methods @OP:

1) create a new coroutine each time and run it
2) create a bindable event, connect the function to event.Event:connect(), and after the loop, use event:Fire()
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
01 Sep 2016 04:34 PM
the event should be the best method for you

local Levitate = function(Brick)
wait(math.random(1,10)/10)
while wait() do
local Origin = Brick.CFrame
Brick.CFrame = Origin*CFrame.new(0,math.sin(tick()),0)
end
end

local event = Instance.new("BindableEvent")
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "PlateLevi" then
event.Event:connect(function() Levitate(v) end)
end
end
event:Fire()
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
01 Sep 2016 04:41 PM
Is any detriment caused by redefining the coroutine each time?

math.randomseed(tick())

for i,v in pairs(workspace:GetChildren()) do
if v.Name == "PlateLevi" then
local Levitate
Levitate = coroutine.wrap(function(Brick)
local Origin = Brick.CFrame
local offset = math.random(1,5)/10
while wait() do
Brick.CFrame = Origin*CFrame.new(0,math.sin(tick()-offset)*10,0)
end
end)
Levitate(v)
wait(math.random(1,10)/10)
end
end

Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
01 Sep 2016 04:46 PM
it causes lag

thats why i said use bindables
Report Abuse
grot327 is not online. grot327
Joined: 15 Jun 2010
Total Posts: 14
01 Sep 2016 05:21 PM
^ wrong

In this scenario that couroutine can cause no memory leaks because it is dependent on Brick existing. As soon as Brick is removed, it will error and ROBLOX will clean it for you eventually.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
01 Sep 2016 05:22 PM
easy answer: use spawn()


Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
01 Sep 2016 05:22 PM
yes it does cause lag

if you run about 100 coroutines it lags a lot more then if you run 1 event

it works on my midi player
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
05 Sep 2016 12:49 PM
Is spawn() better than the bindable event?


Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
05 Sep 2016 01:26 PM
local parts = { }
local levitate = coroutine.wrap(function()
while true do
for idx = 1, len do
parts[idx] = parts[idx].CFrame * CFrame.new(0, math.sin(tick()), 0)
end
wait()
end
end)()

for i,v in pairs(workspace:GetChildren()) do
if v.Name == "PlateLevi" then
parts[#parts + 1] = v
wait(math.random(1,10)/10)
end
end
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