Sometimes when you use CaptureService:CaptureScreenshot() in studio the onCaptureReady callback never fires depending on what’s actively rendered in the viewport. The exact conditions this happens under are unclear, but a solid color seems to cause the issue to occur consistently.
Observe in the video that when capturing the skybox there’s no issue printing the temporary capture uri that results from the CaptureScreenshot method. However, when enabling the screen gui (which is simply a solid black frame) the CaptureScreenshot method never fires the onCaptureReady callback.
I ran into this as well with my own plugin that uses CaptureService after I updated studio to the latest version. The weird part about it is that I only consistently run into it when my viewport’s resolution is under 600x600.
My repro is a little bit different:
Set your viewport’s resolution to 512x512 with the Device Emulator (or just resize studio)
Run the snippet below and watch it eventually fail to take a screenshot
local TIMEOUT_DURATION = 10
local SCREENSHOT_COUNT = 100
local function takeCapture()
local takenScreenshotTempAssetId = nil
local startTime = tick()
local CaptureService = game:GetService("CaptureService")
CaptureService:CaptureScreenshot(function(tempAssetId)
takenScreenshotTempAssetId = tempAssetId
end)
repeat task.wait() until takenScreenshotTempAssetId or (tick()-startTime) > TIMEOUT_DURATION
return takenScreenshotTempAssetId
end
for index = 1,SCREENSHOT_COUNT do
workspace.Camera.CFrame *= CFrame.fromEulerAnglesYXZ(
math.random() * math.pi,
math.random() * math.pi,
0
)
game:GetService("RunService").PreRender:Wait()
print(`Capturing screenshot {index}/{SCREENSHOT_COUNT}`)
local takenCapture = takeCapture()
if takenCapture==nil then
warn(`Failed to capture screenshot {index}/{SCREENSHOT_COUNT}`)
break
end
print(`Captured screenshot {index}/{SCREENSHOT_COUNT}`)
end