The dxCreateScreenSource function creates the screenSource element. (it can fail if there is not enough video memory, which results in returning the value false instead)
Important:
Elements can't be directly saved inside variable, a variable can only point to an element (see userdata). Thus overriding the value of variable screen, does not delete the previous element. Which leads to a memory leak.
Recommendation:
The screenSource texture element should only be created ones at the top of your resource.
Or you can do something like this:
if not screen then screen = dxCreateScreenSource(sx, sy) end -- of not exist, attempt to create the screenSource texture
if screen then dxUpdateScreenSource(screen, true) end -- if exist, update the screenSource
@Korea
(If you want to me to update your current example, feel free to ask below. Also this topic might be better of at scripting > tutorials, but it is your choice. )