Ruby Script - msf/core (LoadError)

Hello everyone. Ive been having issues for a while now with running exploit-db ruby scripts that ‘require msf/core’. Ive exhausted my own searches (although admittedly, my search queries might require refining once I know more about what is causing the issue) and wondered if there might be a relatively simple ‘fix’, and/or source I could refer, to resolve the issue.
The error upon running the script is as follows:

Traceback (most recent call last):
2: from 16707.rb:12:in <main>' 1: from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in require’
/usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require’: cannot load such file – msf/core (LoadError)


Now, when I add in the absolute path to msf/core within the exploit script (which on my installation is /usr/share/metasploit-framework/lib/msf/core), it resolved the initial issue (for clairty: I replaced ‘require msf/core’ with ‘require /usr/share/metasploit-framework/lib/msf/core’), but then, predictably, just threw up the same error for the next msf/core resource that was required (within core.rb). I started updating each reference with the absolute path, mainly in core.rb, but after 5 or 6 instances I realised this was not a sustainable fix (not least as there will be a high number of instances required) and I must be overlooking something relatively simple with how the msf/core library is referenced on my machine. Ive even tried a fresh install of Kali incase my numerous attempts at fixing it caused other config issues, but alas no luck yet.

Any help and advice would be much appreciated, i.e. can this be fixed by adding the msf/core path into a variable or other reference so that I don’t need to hard code the absolute path throughout the msf/core scripts?

Thank you,

Maybe this is more about me beter learning to port an MSF script to use as a standalone exploit. Just wasnt sure if there was a way of using scripts that call MSF modules from outside the msfconosle/CL environment. In hindsight, potentially over complicating things!