Why does the coroutine run still after I yield it
local cor = coroutine.create(function()
workspace.Doors.Door.Button.isopen.Changed:Connect(function(f)
if script:GetAttribute("State") == 6 then
if f == false then
print("yield")
coroutine.yield()
end
end
end)
wait(math.random(10, 17))
if script:GetAttribute("State") == 6 then
workspace.Doors.Door.Button.ClickDetector:SetAttribute("Disabled", true)
light1.PointLight.Enabled = false
light1b.isopen.Value = false
light1b.Color = Color3.fromRGB(91, 93, 105)
if workspace.CameraOpen.Value == false then
workspace.CameraOpen.Changed:Wait()
workspace.CameraOpen.Changed:Wait()
else
workspace.CameraOpen.Changed:Wait()
end
end
end)
local cor2 = coroutine.create(function()
workspace.Doors.Door.Button.isopen.Changed:Connect(function(f)
if script:GetAttribute("State") == 6 then
if f == true then
coroutine.yield()
end
end
end)
wait(math.random(20, 30))
--code that's not useful here
end)
end)
the part that resumes the coroutine:
local function manageCoroutines(ope)
if script:GetAttribute("State") == 6 then
if ope == false then
coroutine.resume(cor2)
else
coroutine.resume(cor)
end
end
end
manageCoroutines(workspace.Doors.Door.Button.isopen.Value)
workspace.Doors.Door.Button.isopen.Changed:Connect(function(f)
manageCoroutines(f)
end)
I think the problem has to do with math.random(10, 17)