*Someone told me that you can use coroutines in order to prevent a glitch from happening. I tried it, and it still glitches.
I ran the server. The moving part successfully moved until five seconds. It blinked blue and orange.
This is the "before" of the script.*
while true do
while true do
script.Parent.CFrame=script.Parent.CFrame+Vector3.new(0,0,0.5)
wait()
script.Parent.BrickColor=BrickColor.new("Bright orange")
end
wait(5)
while true do
script.Parent.CFrame=script.Parent.CFrame+Vector3.new(0,0,-0.5)
wait()
script.Parent.BrickColor=BrickColor.new("Bright orange")
end
wait(5)
end
This is the "after" of the script when I converted the loops into coroutines.
local Loop1 = coroutine.create(function()
while true do
script.Parent.CFrame=script.Parent.CFrame+Vector3.new(0,0,0.5)
script.Parent.BrickColor=BrickColor.new("Bright blue")
wait()
end
end)
local Loop2 = coroutine.create(function()
while true do
script.Parent.CFrame=script.Parent.CFrame-Vector3.new(0,0,0.5)
script.Parent.BrickColor=BrickColor.new("Bright orange")
wait()
end
end)
while true do
coroutine.resume(Loop1)
coroutine.yield (Loop2)
wait(5)
coroutine.resume(Loop2)
coroutine.yield (Loop1)
wait(5)
end
What's wrong with the "after" code, and what can I do to fix the "before" code?

1 comment
You can not call 'coroutine.yield' outside of a Coroutine: It must be used inside of one. ROBLOX Wiki Documentary on 'Yeild': http://wiki.roblox.com/index.php?title=Coroutine.yield#coroutine.yield