Scope
Scopes are used for performance optimizations. Any client objects that get loaded are placed into a Scope that will automatically clean up everything contained within it when it unloads, in order to prevent lingering Instances and connections from using unnecessary processing and memory.
Properties
instance
Scope.instance:
Instance?
The scope's instance.
scriptPath
Scope.scriptPath:
string?
The scope's script path.
rootScope
Scope.rootScope:
Scope
The scope's root scope.
parentScope
Scope.parentScope:
Scope
The scope's parent scope.
id
Scope.id:
string
The scope's ID.
tower
Scope.tower:
string
The tower's name.
clientObjects
Scope.clientObjects:
Instance
The tower's client objects container.
shared
Scope.shared:
{
[
string
]
:
any
}
A shared table across every single scope inherited by the rootScope
repository
Scope.repository:
{
[
string
]
:
any
}
A table of every single repository script that is currently loaded.
active
Scope.active:
boolean
A variable
activeScripts
All of the current scripts running
Functions
log
Scope:
log
(
data:
any
) →
(
)
Logs the provided data
table into the output.
add
Scope:
add
(
...:
T...
) →
T...
Adds the given items into the Scope, automatically cleaning it up when the Scope unloads. All of the items that are passed in to this function will be returned right back.
INFO
It is important that you put all of your Instances and Connections in this function to be cleaned up when the player leaves the tower. Any functions passed in will run when it is time to clean up.
CAUTION
This function will throw an error if used during the scope's cleanup process.
inherit
Scope:
inherit
(
data:
any
) →
(
)
Creates a new child Scope within the current Scope. Used for client objects that have the capability of spawning other client objects, so cloned models can be cleaned up without the entire object's scope being removed.
remove
Scope:
remove
(
item:
any
,
doNotCleanup:
boolean?
) →
(
)
Removes the given item from the Scope. If doNotCleanup
is set, the object
will not be automatically destroyed along with this.
cleanup
Scope:
cleanup
(
defer:
boolean?
,
destroy:
boolean?
) →
(
)
Cleans up the Scope.
If defer
is set, the cleanup will be deferred rather than occuring immediately.
If destroy
is set, the Scope will be fully destroyed rather than only cleaning up.
attach
Attaches the Scope to the given instance
, cleaning up the Scope if
the instance gets destroyed.
spawn
Scope:
spawn
(
fn:
(
T...
)
→
...unknown
,
...:
T...
) →
(
)
Runs task.spawn
with the given function and adds it to the Scope, cancelling
it if the Scope unloads while the task is running.
defer
Scope:
defer
(
fn:
(
T...
)
→
...unknown
,
...:
T...
) →
(
)
Runs task.defer
with the given function and adds it to the Scope, cancelling
it if the Scope unloads while the task is running.
delay
Scope:
delay
(
seconds:
number
,
fn:
(
T...
)
→
...unknown
,
...:
T...
) →
(
)
Runs task.delay
with the given delay/function and adds it to the Scope, cancelling
it if the Scope unloads while the task is running.