Script

Show Deprecated

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:

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

Hello World

1print("Hello, world")

Summary

Properties

The code to be executed.

Events

Methods


Returns a hash of the script's source.

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:


1print("Hello world!")
2

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.

Events

Methods

GetHash

Local User Security

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:

  1. 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.
  2. The same data (e.g. script source) always generates the same hash.
  3. Different data (e.g. different script sources) generate unique hashes. It is highly unlikely that two different sources will generate the same hash.

Limitations

The hash function has several limitations, including:

  • If the script's LinkedSource property is set, then this method will return the empty string.
  • This item is protected. Attempting to use it in a Script or LocalScript will cause an error.

Returns

The 32 character hash value generated by the hash function.

Code Samples

Hashing a Script's Source

1-- Script named HelloScript in workspace
2local function printHello()
3 print("Hello world!")
4end
5
6printHello()
7
8-- Command line
9local targetScript = game.Workspace.HelloScript
10print(targetScript:GetHash())