Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a new script instance with a source set from the script?

So i've been looking all over the internet for this to no avail. So basically i'm trying to make a localscript with a preset source instead of editing it.

I tried multiple methods that didn't work and always gave out the same lacking permission error.

Please if someone has a method on how to do that i beg you tell me how you do it because i really need it right now.

Thanks in advance.

3 answers

✓ Accepted answer

Hey! I recently dealt with this problem myself, and i got a solution! So what you want to do, from what I can tell, is create a script that has already got the code, so it can happen in game! What I would recommend you do is create the script/localscript in 'ReplicatedStorage', and then access it by referencing it in another script for the part.

For example if you want to create a new part and put the script inside of it you would do

local Script = game.ReplicatedStorage.script:clone()
local part = instance.new("Part")

Script.parent.parent = part

And that would put a copy of the script into the new part!

Unfortunately, a script's source can only be indexed via the command bar and plugins. I suppose you could create a local plugin that creates a script and sets the source for you. A tutorial on how to make plugins can be found here.

If you have any further questions, shoot me a DM on Discord, @artblart#3386 and I'd be happy to answer.

Edit: spelling

This discussion is preserved as it was. New answers, comments, and votes are closed.