Instances - Xeptix/framework GitHub Wiki

Framework Instances

The framework takes control over all instances in your scripts enabling you to fully customize them however you may desire. These are all the API changes we make to instances.

* optional argument

root

The root instance is the base roblox instance. The instance Instance derives from root, and all instances in roblox derive from Instance. This means that all instances are derived from root, thus, they have all of the api members below.

operation #

<number> #root

Returns the number of children root has. This is the exact same as doing #root:GetChildren(). GetChildren is a roblox api member. All instances have this functionality.

Example:

print(#game.Workspace) --> 13

method IsA

<boolean> root:IsA(<string>)

Returns true if <string> is a the ClassName of root, or a derived class of root. This is a roblox api member that was modified to properly return true for the framework's custom instances.

Example:

print(game.Workspace.BasePlate:IsA("Part")) --> true
print(game.Workspace.BasePlate:IsA("BasePart")) --> true
print(game.Workspace.BasePlate:IsA("root")) --> true
print(game.Workspace.BasePlate:IsA("XeptixObject") --> true
print(game.Workspace.BasePlate:IsA("Dolphin")) --> false

method root:FindFirstChildOfClass

<mixed> root:FindFirstChildOfClass(<string>, <*boolean>)

Returns the first child that IsA <string>. If <*boolean> is true, root is recursively searched for a child with the ClassName <string>. This is a roblox api member that was modified to both support custom framework instances, and allow recursive searches which roblox api does not provide.

Returns nil if a child is not found.

Example:

print(workspace:FindFirstChildOfClass("PartInsideOfAModel")) --> nil
print(workspace:FindFirstChildOfClass("PartInsideOfAModel", true)) --> PartInsideOfAModel

method root:FindFirstChildWithProperty

<mixed> root:FindFirstChildWithProperty(<string>, <*mixed>, <*boolean>)

Returns the first child that has the property <string>. If <*mixed> is not nil, then the property <string> must be equal to <*mixed>. If <*boolean> is true, root is recursively searched for a child with the property <string>

Returns nil if a child is not found.

Example:

print(workspace:FindFirstChildWithProperty("Name")) --> Camera
print(workspace:FindFirstChildWithProperty("hey")) --> nil
print(workspace:FindFirstChildWithProperty("Value", 69)) --> SomeNumberValue
print(workspace:FindFirstChildWithProperty("Value", workspace.BasePlate)) --> SomeObjectValue

method root:WaitForChildOfClass

<mixed> root:WaitForChildOfClass(<string>, <*number>)

Waits for and returns the first child that IsA <string>. If <*number> is not nil, the function will return nil after <*number> seconds have passed without finding a child.

Only returns nil on timeout.

Example:

print(workspace:WaitForChildOfClass("NonExistantPart", 5)) --> (after 5 seconds) nil
print(workspace:WaitForChildOfClass("Camera")) --> Camera

method root:Recursive

<void> root:Recursive(<function>)

Recursively loops through root and all descendants, calling <function> on each descendant.

Example:

workspace:Recursive(function(descendant)
    print(descendant)
end)

Output:

Camera
Terrain
BasePlate
Model
PartInsideModel
Fire

method root:HasProperty

<boolean> root:HasProperty(<string>)

Returns true if root has a property named <string>, otherwise it returns <false>. This allows you to safely check if a property is existent without error.

Returns false for Events and Methods.

Example:

print(game:HasProperty("CreatorId")) --> true

method root:HasMethod

<boolean> root:HasMethod(<string>)

Returns true if root has a method named <string>, otherwise it returns <false>. This allows you to safely check if a method is existent without error.

Returns false for Events and Properties.

Example:

print(game:HasMethod("FakeMethod")) --> false

method root:HasEvent

<boolean> root:HasEvent(<string>)

Returns true if root has an event named <string>, otherwise it returns <false>. This allows you to safely check if an event is existent without error.

Returns false for Methods and Properties.

Example:

print(game:HasEvent("ChildAdded")) --> true

method root:SetProperty

<void> root:SetProperty(<string>, <mixed>)

Sets property <string> of root to <mixed>. <mixed> can be anything.

You can not create properties by performing root.NewProperty = 1337 - you must use this method. You must only perform this method one time - once a property is created, even if set to nil, it does not need to be recreated.

Note - custom properties replicate cross-script, however they do not replicate from the server to clients and vice-versa. This is for security and performance reasons.

Example:

workspace.Part:SetProperty("BulletOwner", Player1)
print(workspace.Part:HasProperty("BulletOwner")) --> true
print(workspace.Part.BulletOwner.Name) --> Player1
workspace.Part.BulletOwner = Player2
print(workspace.Part.BulletOwner.Name) --> Player2

method root:SetMethod

<void> root:SetMethod(<string>, <function>)

Sets method<string> of root to <function>. The arguments of <function> are the arguments supplied when calling the custom method.

You can not create custom methods by performing root.NewMethod = function() end - you must use this method.

Under all circumstances, unlike SetProperty, this must be used to update an existing method.

Note - custom methods replicate cross-script, however they do not replicate from the server to clients and vice-versa. This is for security and performance reasons.

Example:

workspace.Part:SetMethod("FadeTransparency", function(transparency)
    --code
end)

workspace.Part:FadeTransparency(1)
print(workspace.Part:HasMethod("FadeTransparency")) --> true

method root:SetMethod

<event> root:SetMethod(<string>)

Creates and returns an <event> named <string> inside of root.

You can not create custom events by performing root.NewEvent = blah - you must use this method.

If the method <string> already exists, it will be replaced with a new event. The old event will not disconnect, however it will never be fired again. Behavior may change in the future to disconnect events when overwritten.

Note - custom events replicate cross-script, however they do not replicate from the server to clients and vice-versa. This is for security and performance reasons.

Example:

local e = workspace.Part:SetEvent("test")
e.test:connect(function(...)
    print(...)
end)

local c = workspace.Part.test:connect(function(...)
    print(...)
end)

e:fire("hello","world") --> hello world (2x)
c:disconnect()
workspace.Part.test:fire("hey","again") --> hey again (1x)
print(workspace.Part:HasEvent("test")) --> true

method root:LockProperty

<void> root:LockProperty(<string>, <number>)

Locks all properties, events, and methods with the index <string>. LockMode (<number>) must be a number from 1 to 5.

The current LockModes are...

  • 1 - Prevent Reading
  • 2 - Prevent Writing
  • 3 - Prevent Reading & Writing
  • 4 - Prevent Server-Side Usage
  • 5 - Prevent Client-Side Usage

You must call LockMode 4 from the server - likewise, LockMode 5 can only be called from clients.

You can not unlock once locked. You can only call each of the three LockModes once per instance. Locking the same LockMode on an instance twice will throw an error.

Use CanReadProperty and CanModifyProperty to test if a property, method, or event is locked.

Example:

local p = workspace.Part
p:LockProperty("Name", 2) -- lock changing the name
pcall(function() p.Name = "test" end) -- errors
print(p.Name) --> Part
p:LockProperty("Name", 1) -- lock reading the name
local p2 = workspace.Part -- does not error
print(p2.Name) --> errors

method root:CanReadProperty

<boolean> root:CanReadProperty(<string>)

Returns true if the property, event, or method <string> of root can be read without throwing an error, otherwise it returns <false>. This allows you to safely check if a property is locked without error.

Example:

print(workspace.Part:CanReadProperty("Name")) --> true
print(workspace.Part.Name) --> Part
workspace.Part:LockProperty("Name", 3)
print(workspace.Part:CanReadProperty("Name")) --> false
print(workspace.Part.Name) --> errors

method root:CanModifyProperty

<boolean> root:CanModifyProperty(<string>)

Returns true if the property, event, or method <string> of root can be modified without throwing an error, otherwise it returns <false>. This allows you to safely check if a property is locked without error.

Example:

print(workspace.Part:CanModifyProperty("Name")) --> true
workspace.Part.Name = "PartB"
print(workspace.PartB.Name) --> PartB
workspace.PartB:LockProperty("Name", 3)
print(workspace.PartB:CanModifyProperty("Name")) --> false
workspace.PartB.Name = "Part" --> errors

game

The game instance is the DataModel roblox instance. All instances that are parented are a descendant of game, including services. If you have any experience with roblox lua, then there's no need for me to explain any further ;)

method GetService

<Instance> game:GetService(<string>)

Returns a Framework Service with the name <string>, or a Roblox Service. Throws an error if the service does not exist. Use game:FindService() to check if a service exists.

Example:

print(game:GetService("BadgeService")) --> BadgeService
print(game:GetService("Lighting")) --> Lighting
print(game:GetService("FrameworkService")) --> FrameworkService

method FindService

<boolean> game:FindService(<string>)

Returns true if a Framework Service with the name <string>, or a Roblox Service with the name <string> exists. Otherwise it returns false. Use game:GetService() to get an existent service.

Example:

print(game:FindService("BadgeService")) --> true
print(game:FindService("hello")) --> false
print(game:FindService("FrameworkService")) --> true

method GetFrameworkModule

<Instance> game:GetFrameworkModule()

Returns the XeptixFramework ModuleScript.

This is an internal function and may change without notice. Be careful when using internal items!

property Info

<string> game.Info

Not documented.

This is an internal property and may change without notice. Be careful when using internal items!

⚠️ **GitHub.com Fallback** ⚠️