Script
A Script is a type of Lua code container that will run its contents on the server. By default, Scripts have print("Hello, world") as their contents. The instant that the following conditions are met, a Script's Lua code is run in a new thread:
- Disabled property is false
- The Script object is a descendant of the Workspace or ServerScriptService
The Script will continue to run until the above conditions are not met, it terminates or it raises an error (unless that error is raised by a function connected to some event that is firing). Additionally, the thread will be stopped if the Script or one of its ancestors is destroyed. A script will continue to run even if the Parent property is set to nil (and the Script is not destroyed).
It has access to server-side objects, properties and events. For example, Scripts can award badges to players using BadgeService, while a LocalScript on the client cannot. Actions taken by LocalScripts that are not replicated (due to Workspace.FilteringEnabled) will not be visible to Scripts.
Code Samples
print("Hello, world")
Summary
Properties
Methods
Events
Properties
Source
A script's Source is the code to be executed. Modifying the code within a script modifies the source code executes when the script runs.
For instance, given a script containing the line:
print("Hello world!")
The script's source is the "print("Hello world")" command because it is what will be executed when the script runs, leading to "Hello world" being printed in the command line.
This item is protected. Attempting to use it in a Script or LocalScript will cause an error.
If you want to read or modify a script that the user has open, consider using the ScriptEditorService to interact with the Script Editor instead.
Code Samples
-- Script named HelloScript in workspace
local function printHello()
print("Hello world!")
end
printHello()
-- Command line
local targetScript = workspace.HelloScript
print(targetScript.Source)