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 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.
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:
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.
The GetHash function returns a hash of the script's source.
What is a Hash
A hash is a string of characters produced by a cryptographic algorithm that maps data of arbitrary size, since scripts can be short or long, to data of a fixed size, a string of a fixed length. Although they have several uses, hashes are often used to determine the integrity of data and make it faster to look up data. If you compare two pieces of data and their hashes do not match, then the data has changed.
Hashes have three key properties:
- They are often of fixed lengths. Since the function uses a hashing algorithm known as MD5, this function always generates hashes consisting of 32 hexadecimal (number and letter) characters.
- The same data (e.g. script source) always generates the same hash.
- Different data (e.g. different script sources) generate unique hashes. It is highly unlikely that two different sources will generate the same hash.
The hash function has several limitations, including:
- If the script's LinkedSource property is set, then this method will return the empty string.
1-- Script named HelloScript in workspace2local function printHello()3 print("Hello world!")4end56printHello()78-- Command line9local targetScript = game.Workspace.HelloScript10print(targetScript:GetHash())