getluastate

Returns the LuaStateProxy for an Actor, script, or the current state.

Syntax

getluastate(actor_or_script: (Actor | LocalScript | ModuleScript | Script)?) -> LuaStateProxy?

Parameters

ParameterTypeDescription
actor_or_scriptActor, BaseScript, or nilThe Actor or script to get the state for. If omitted, returns current state

Returns

TypeDescription
LuaStateProxy?The matching state, or nil if it is unavailable

Description

If no argument is provided, getluastate returns the current Lua state.

Example

-- Get current state
local currentState = getluastate()
print("Current state ID:", currentState.Id)

-- Get state for an actor
local actor = getactors()[1]
local actorState = actor and getluastate(actor)
if actorState then
    print("Actor state ID:", actorState.Id, "Is Actor:", actorState.IsActorState)
end

Get State for Script

-- Get state for a specific script
local script = workspace.SomeScript
local scriptState = getluastate(script)
print("Script state ID:", scriptState.Id)

Access State Properties

local state = getluastate()
print("State ID:", state.Id)
print("Is Actor State:", state.IsActorState)

-- Get all actors for this state
local actors = state:GetActors()
print("Actors in state:", #actors)