How to use Script.Source?

Hey! I’m making a leaderstats creator plugin.
How do I use Script.Source? Basically just

Script.Source = print("Hello World")

or

Script.Source = local var1 = "idk" print(var1)

?
If I do that, it will be underlined red.
Thank you!

1 Like

From this website:
This item is protected. Attempting to use it in a Script or LocalScript will cause an error.

2 Likes

^, I’m making a plugin, not a script.

Ok, but isn’t a plugin just a script if i’m not mistaken?

1 Like

Script.Source takes a String:

Script.Source = "print(\"Hello World\")"
13 Likes

Script.Source takes a string, the code like this “print(‘hello’)”

1 Like

Yes it is, but you can access Script.Source when publishing the script as a plugin.

1 Like

Access .Source of other scripts, and of it self, I suppose.

1 Like

what you can do instead is:

Script.Source = 'print("Hello World")'

so every time you want the script to have a string in it you don’t have to write: \" but you can just write "

4 Likes

So it’s basically like loadstring()?

3 Likes

Not really, you can change a script with it.
It’s often used by plugins, for example:

local newScript = Instance.new("Script")
newScript.Source = 'print("New script!")'
newScript.Parent = game:GetService("ServerScriptService")

would insert a script that has print("New script!") in it into ServerScriptService.

2 Likes

You cannot change a script’s source, only plugins and the command bar can do that.

You’ll receive the following error if you attempt it:
The current identity (2) cannot Source (lacking permission 1)

Another note is that you can’t even read the source (only plugins and the command bar can do that as well).