# 오브젝트 참조

## 개요

Service, Part, Player 등 오브젝트의 유형에 따라 다양한 방식으로 필요한 오브젝트를 가져올 수 있습니다.

## Service 가져오기

Service란 게임 내에서 특정한 기능을 수행하도록 설계된 기본 제공 시스템을 의미합니다.

```lua
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local StarterPlayer = game:GetService("StarterPlayer")
local Players = game:GetService("Players")
...
```

## 부모 오브젝트 참조

<pre class="language-lua"><code class="lang-lua">-- 오브젝트의 부모
<strong>local ParentPart   = Part.Parent
</strong>
-- 스크립트의 부모
local ScriptParent = script.Parent
</code></pre>

## 자식 오브젝트 참조

```lua
-- 주소값으로 오브젝트 반환 (오브젝트가 로드되기 전이면 실패할 수 있습니다.)
local ChildPart1 = Workspace.ChildPart

-- 이름에 해당하는 첫번째 오브젝트 반환
local ChildPart2 = Workspace:FindFirstChild("ChildPart") 

-- 오브젝트가 반환될때까지 대기 
local ChildPart3 = SomePart:WaitForChild("ChildPart")
```

## 모든 자식 가져오기

Part의 계층 구조가 아래와 같을 때

<div align="left"><img src="/files/28Dy2MwdLekRfdrz21a8" alt=""></div>

```lua
local Part = Workspace:WaitForChild("Part")


-- 부모 오브젝트(Part)의 모든 첫번째 자식 오브젝트를 반환
local Children = Part:GetChildren() 

for _, child in ipairs(Children) do
    -- ChildPart1, ChildPart2 출력
    print(child.Name) 
end


-- 부모 오브젝트(Part)의 모든 하위 자식 오브젝트를 반환
local Descendants = Part:GetDescendants() 

for _, descendant in ipairs(Descendants) do
    -- ChildPart1, ChildPart1-1, ChildPart2, ChildPart2-1 모두 출력
    print(descendant.Name)
end
```

## 모든 플레이어 가져오기

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

for i = 1, #PlayerList do
    print(PlayerList[i])
end
```

## LocalPlayer 가져오기 (LocalScript)

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

## Player로 Humanoid 가져오기

```lua
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
```

## Humanoid로 Player 가져오기

```lua
local Character = Humanoid.Parent
local Player = Players:GetPlayerFromCharacter(Character)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overdare.com/korean/manual/script-manual/get-started/object-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
