The title may be a bit confusing so here's a better breakdown of what I am asking.
Is it possible to, for example take script 2's code
-- hi this is script 2
and copy and paste it using script 1
-- hi this is script 1 local script2code = game.ReplicatedStorage.Script2:CloneCode -- just an example script2code:PasteCode -- also just an example
I've looked around in module scripts a little bit and I'm pretty sure they're not what I'm after.
Any advice, and potential answers are appreciated.
Copy and pasting a function from one script to another, yields the same result as calling that function in another script using a modulescript. I don't think copying the text is possible unless you make a complex function that takes parameters to do so. Your best option is to just use a module script to use the code in that module script in other scripts (which is the same result as what you are trying to do.)
the code below is in a module script. Pretend the name of this script is "PrintModule" and its in the workspace.
local module = { yourfunction = function(textyouwanttoprint) print(textyouwanttoprint) end, }
In the normal script
local module2 = require(game.Workspace.PrintModule) local texttoprint = "ModuleCalled" module2.yourfunction(texttoprint)
The output will have printed "ModuleCalled"
The function in the module can be replaced with pretty much anything, if you are looking to call that function in other scripts. You want to copy code from one script to another, instead of that this puts code in a module script which can be called from another script. Which runs that code in the script you called it from.
Use a ModuleScript, they are essentially just extensions of the script that runs them. Here is an example:
Normal Script:
local modulething = require(module location or module id) modulething.Swag("hello")
Module Script:
local module = {} module.Swag = function(t) print(t) end return module