API:ProtectedString

A ProtectedString is a data type that cannot be read or written to by LocalScripts or Scripts. For example, the Source property of Script is a ProtectedString. Attempts to read it from a normal script result in an error:

print(Workspace.Script.Source)

This would print an error:

Friday Sep 22 09:47:56 2017 - Source is not a valid member of Script

This is because ProtectedStrings are not recognized by Scripts or LocalScripts. You can only access them via the Command bar, CoreScripts, or Plugins.

There is no way to create a ProtectedString value.

Getting around the Source property

This is a major obstacle that gets in the way of many scripters all around Roblox. Many scripters will try to set the Source property the conventional way:

Workspace.Script.Source = [[print("Hello, World!")]]

Unfortunately, this does not work. One way to get around this is to add a StringValue to simulate the Source of the script, and then use the loadstring function on the StringValue's Value.

  • Tree-collapse.png
    Workspace
    Workspace
    • Tree-collapse.png
      Script
      Script
      • StringValue
        SourceCode

The Script's source:

script.SourceCode.Changed:connect(function()
	loadstring(script.SourceCode.Value)()
end)

The source code's Value:

Workspace.Script.SourceCode.Value = [[print("Hello, World!")]]
Hello, World!