# ScriptSignal

## Overview

ScriptSignal is an event system that detects a specific condition in game and automatically executes the functions connected to that signal.

When the signal is triggered, the connected user-defined functions are called. If necessary, information associated with the event is passed as parameters to support more flexible implementation of various interactions.

## Constructors

## Properties

## Methods

### Connect

Registers a function to be called when the event occurs and returns a ScriptConnection object that manages the connection state.

After registration, the specified function is automatically executed whenever the event is triggered, and the returned connection object can be used to disconnect from the event at any time.

#### Parameters

| `function` func | Specifies the user-defined function to connect to the event signal. |
| --------------- | ------------------------------------------------------------------- |

#### Return

| `ScriptConnection` | A ScriptConnection object that can be used to manage signal connection. |
| ------------------ | ----------------------------------------------------------------------- |

#### Code Samples

```lua
local Players = game:GetService("Players")

local function EnterPlayer(player)
    print("EnterPlayer : ", player.Name)
end
Players.PlayerAdded:Connect(EnterPlayer)
```

### Once

Registers a function to be executed only once when the event occurs and returns a ScriptConnection object that manages the connection state.

Unlike Connect, the connection is automatically disconnected just before the first event is delivered, which is suitable for processing a single call without requiring separate disconnection.

#### Parameters

| `function` func | Specifies the user-defined function to connect to the event signal. |
| --------------- | ------------------------------------------------------------------- |

#### Return

| `ScriptConnection` | A ScriptConnection object that can be used to manage signal connection. |
| ------------------ | ----------------------------------------------------------------------- |

#### Code Samples

```lua
local Players = game:GetService("Players")

local function EnterPlayer(player)
    print("EnterPlayer : ", player.Name)
end
Players.PlayerAdded:Once(EnterPlayer)
```

### Wait

Blocks the current thread until the signal fires once, then returns the arguments that were passed when the signal was fired.&#x20;

Its use is recommended when you only need to wait once—for example, until a character is ready or until a child is added.

#### Parameters

#### Return

| TextText  | TextText                                                                                   |
| --------- | ------------------------------------------------------------------------------------------ |
| `Variant` | The arguments passed when the signal was fired. The number and types depend on the signal. |

#### Code Samples

```lua
-- LocalScript
-- In LocalScript: wait for character creation and get the Character instance
local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()


-- Script or LocalScript
-- Get the instance that is added as a child of a specific instance
local Workspace = game:GetService("Workspace")
local Folder = Workspace :FindFirstChild("MyFolder")
local AddedChild = Folder.ChildAdded:Wait()
```

## See also

{% content-ref url="../../../manual/script-manual/events-and-communication/event" %}
[event](https://docs.overdare.com/manual/script-manual/events-and-communication/event)
{% endcontent-ref %}
