doing getimage on the viewport texture returns the image with the function "getpixel(x,y)"
Replacing getdata with getimage should work but it will lag if it is overused
Note on the viewport texture
"Note: This will fetch the texture data from the GPU, which might cause performance problems when overused."
and another thing you should do to prevent black textures or past textures is wait until
the texture fully loads
"Note: When trying to store the current texture (e.g. in a file), it might be completely black or outdated if used too early, especially when used in e.g. Node.ready(). To make sure the texture you get is correct, you can await RenderingServer.framepost_draw signal."
put await RenderingServer.framepostdraw
before you get the viewport texture to let it load fully, then you can grab the full version of it