Volt

on_actor_state_created

Event fired when an Actor Lua state is created, before any scripts are executed.

Syntax

on_actor_state_created: BindableEvent

Description

on_actor_state_created is a global BindableEvent that fires when a new Actor Lua state is created, before any scripts are executed on that state. This allows you to set up hooks or inject code into new actor states as they're created.

Event Arguments

ArgumentTypeDescription
actorActorThe Actor instance whose state was created

Example

on_actor_state_created.Event:Connect(function(actor)
    print("New actor state created:", actor:GetFullName())
    
    -- Get the state for this actor
    local state = getluastate(actor)
    print("State ID:", state.Id)
end)

Setup Hooks on New States

on_actor_state_created.Event:Connect(function(actor)
    local state = getluastate(actor)
    
    -- Execute setup code on the new state
    state:Execute([[
        -- This runs before any scripts execute on the actor
        print("Actor state initialized!")
    ]])
end)

With Communication Channel

local id, channel = create_comm_channel()
channel.Event:Connect(function(actorName)
    print("Actor state ready:", actorName)
end)

on_actor_state_created.Event:Connect(function(actor)
    local state = getluastate(actor)
    state:Execute([[
        local channelId = ...
        local channel = get_comm_channel(channelId)
        channel:Fire(script:GetFullName())
    ]], id)
end)

Notes

  • Fires before any scripts execute on the actor state
  • Useful for setting up hooks or injecting code early
  • The state is fully initialized but empty when this fires

On this page