of     1   

Lurrrch
#180769519Thursday, December 31, 2015 8:50 PM GMT

I'm trying out coroutines in my latest project, and I'm a little confused. Yield, in its basic form, seems like such a simple thing... it's supposed to pause the coroutine, no? But when I run this... local backupface = coroutine.wrap(function() local character = player.Character print("Character is " .. character.Name .. " for backupface") character.Head:WaitForChild("face").Parent = nil print("Backupface complete") coroutine.yield() wait(1) print("cour resumed") end) ...the entire thing runs, including the print at the end. "Backupface" is only being called once, but the yield seems to be completely ignored and it just goes through regardless. I'm probably missing something really obvious here; this is my first time touching these. Any help is welcome!
chimmihc
#180770149Thursday, December 31, 2015 8:58 PM GMT

Look at this: x = coroutine.wrap(function() print(1) coroutine.yield() print(2) end) x() --> 1 x() --> 2 x() --> cannot resume dead coroutine
Lurrrch
#180771365Thursday, December 31, 2015 9:13 PM GMT

? I know it cannot resume when dead, but I'm saying that it's ignoring the yield completely. It should be able to "resume" twice, one for the initial run and one that would do the final print after the yield, but it does it all in one run. If your example ran with the same problem I'm having, it would print 1 and 2 in the same go.
Lurrrch
#180771978Thursday, December 31, 2015 9:22 PM GMT

Basically my coroutine.yield() is not yielding and I'm totally confused as to why that is.
chimmihc
#180772590Thursday, December 31, 2015 9:31 PM GMT

There is no problem with the code in the first post, it runs as expected. -- local player = game.Players.LocalPlayer local backupface = coroutine.wrap(function() local character = player.Character print("Character is " .. character.Name .. " for backupface") character.Head:WaitForChild("face").Parent = nil print("Backupface complete") coroutine.yield() wait(1) print("cour resumed") end) backupface() -- output: Character is Player for backupface Backupface complete
Lurrrch
#180772734Thursday, December 31, 2015 9:33 PM GMT

And it didn't also print "cour resumed" in that same run??? Why is it doing it for me? This is odd.
dennis96411
#180773863Thursday, December 31, 2015 9:49 PM GMT

You're not calling it multiple times, are you?
Lurrrch
#180774149Thursday, December 31, 2015 9:52 PM GMT

That's what my first thought was, but no, I don't see any way that could be happening. It's called when the player's character is added, and that's the only way it can be.
dennis96411
#180774769Thursday, December 31, 2015 10:01 PM GMT

Can you give us the code where that actually happens?
Lurrrch
#180775015Thursday, December 31, 2015 10:05 PM GMT

player.CharacterAdded:connect(function() runit() end) Just tested it with debounces to see if it was firing twice somehow. It definitely wasn't - fires once, still calls coroutine twice.
dennis96411
#180775994Thursday, December 31, 2015 10:18 PM GMT

It's has to be being called twice somewhere. Is runit a separate function?
Lurrrch
#180776963Thursday, December 31, 2015 10:30 PM GMT

Yes, and I just found the part that makes it run through. When I delete this section of code in "runit," the yield works: local human = character:findFirstChild("Humanoid") if human ~= nil then -- making human invisible character:findFirstChild("Head").Transparency = 1 character:findFirstChild("Torso").Transparency = 1 character:findFirstChild("Left Arm").Transparency = 1 character:findFirstChild("Right Arm").Transparency = 1 character:findFirstChild("Left Leg").Transparency = 1 character:findFirstChild("Right Leg").Transparency = 1 if character:findFirstChild("Head"):findFirstChild("face") == nil then return end character:findFirstChild("Head"):findFirstChild("face"):remove() if character:findFirstChild("Torso"):findFirstChild("roblox") == nil then return end character:findFirstChild("Torso"):findFirstChild("roblox"):remove() end If I put that section back in, the yield is skipped/the coroutine is run twice. Why?
dennis96411
#180777345Thursday, December 31, 2015 10:36 PM GMT

Maybe when you removed one of those things from the character model, the character gets reloaded? That could explain having the event being triggered twice.
Lurrrch
#180777757Thursday, December 31, 2015 10:41 PM GMT

Yup, I removed the removals and it's working now. I have no idea why that would work like that. But now I have a new problem... Everything loads without error or issue and the yield stays, but the face is just straight up not being removed now. The coroutine is set to wait for and remove the face decal, but it's managing to print "Backupface complete" when the face is clearly still there. What.
dennis96411
#180778323Thursday, December 31, 2015 10:47 PM GMT

Try this: if character:FindFirstChild("Humanoid") then character:FindFirstChild("Head").Transparency = 1 character:FindFirstChild("Torso").Transparency = 1 character:FindFirstChild("Left Arm").Transparency = 1 character:FindFirstChild("Right Arm").Transparency = 1 character:FindFirstChild("Left Leg").Transparency = 1 character:FindFirstChild("Right Leg").Transparency = 1 if character:FindFirstChild("Head"):FindFirstChild("face") then character.head.face:Destroy() end if character:FindFirstChild("Torso"):FindFirstChild("roblox") then character.Torso.roblox:Destroy() end end
dennis96411
#180778394Thursday, December 31, 2015 10:48 PM GMT

Oops, forgot to capitalize head. Use this instead. Try this: if character:FindFirstChild("Humanoid") then character:FindFirstChild("Head").Transparency = 1 character:FindFirstChild("Torso").Transparency = 1 character:FindFirstChild("Left Arm").Transparency = 1 character:FindFirstChild("Right Arm").Transparency = 1 character:FindFirstChild("Left Leg").Transparency = 1 character:FindFirstChild("Right Leg").Transparency = 1 if character:FindFirstChild("Head"):FindFirstChild("face") then character.Head.face:Destroy() end if character:FindFirstChild("Torso"):FindFirstChild("roblox") then character.Torso.roblox:Destroy() end end
Lurrrch
#180779813Thursday, December 31, 2015 11:06 PM GMT

Agh, this is weird. I can keep the removes out of that section, that's fine, I didn't need them there anyway. But now I've got this: local backupface = coroutine.wrap(function() -- while true do print("cour began") local character = player.Character print("Character is " .. character.Name .. " for backupface") -- character.Head:WaitForChild("face").Parent = nil character:WaitForChild("Head") local face = character.Head:WaitForChild("face") if face ~= nil then face:Destroy() end print("Backupface complete") coroutine.yield() wait(1) print("cour resumed") -- end end) And it runs without error or skipping the yield. But it just doesn't destroy the face! Even if I remove the face ~= nil part, making it so that it attempts to destroy the face no matter what, it still runs like it did destroy it without error but the face decal is clearly still there. Why?!?

    of     1