TextDocumentDidClose on plugin:OpenScript()

so i want when the plugin:OpenScript script editor closes, fire a function; but there’s one issue, :GetScript() returns nil

local target
plugin:OpenScript(target)

ScriptEditorService.TextDocumentDidClose:Connect(function(document: ScriptDocument)
   print(document:GetScript()) -- nil
   if document:GetScript() == target then f() end
end

are there any alternatives I could take?

the script that i want to open is a module script btw, if that matters

for some reason plugin:OpenScript on TextDocumentDidChange, when you do :GetScript(), its not equal to the script you passed in