coroutine.yield
does not seem to stop a coroutine with a while loop inside. For example:
local spam = coroutine.create(function() while true do print("oof") wait(1) end end) coroutine.resume(spam) wait(3) --Should print "oof" 3 times coroutine.yield()
Yet the coroutine will continue to print "oof" indefinitely. Does anybody know of a fix for this?
Don't think you can, while
loops cannot be stopped unless break
is called upon, what I would do is I would use a function to do the task.
Use a for loop instead lemme give example:
local f = coroutine.create(function() for i = 1,40 do wait(.05) game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new((math.random(1,3)/10)power,0,0) wait(.05) game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new((-math.random(1,3)/10)power,0,0) end end)
f = coroutine.create(function () while true do wait(.05) game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new((math.random(1,3)/10)power,0,0) wait(.05) game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new((-math.random(1,3)/10)power,0,0) end end)
That how I fixed mine when I had that problem