안녕하세요! 😊 오늘은 로블록스에서 가장 기초적인 퀘스트 시스템을 처음부터 끝까지 만들어보겠습니다.
예제로는 “사과(Apple) 가져오기 → NPC에게 전달하기” 퀘스트를 제작합니다. 초보자분들도 이해할 수 있도록 A to Z 단계별로 하나씩 설명하고, 실제 코드도 함께 보여드리겠습니다.
🔹 1. 기본 구상
퀘스트의 흐름은 다음과 같습니다.
- 플레이어가 NPC와 대화 → 퀘스트 시작
- 맵 어딘가에서 사과 아이템 획득
- 다시 NPC에게 돌아가서 아이템 전달
- NPC가 보상 지급 → 퀘스트 완료
🔹 2. 오브젝트 준비
- NPC 만들기
- Explorer에서 Workspace에 Part를 추가하고, 모양을 NPC처럼 꾸밉니다.
- 이름을 QuestNPC로 변경합니다.
- 아이템(사과) 만들기
- 마찬가지로 Part를 추가하고, 빨간색 구체로 만들어 이름을 Apple로 설정합니다.
- 플레이어가 닿으면 먹을 수 있게 만들 예정입니다.
- GUI (대화창) 준비
- StarterGui에 ScreenGui를 추가합니다.
- 그 안에 TextLabel과 TextButton을 넣어 NPC와 대화할 수 있는 간단한 창을 만듭니다.
- 이름은 각각 QuestLabel, AcceptButton으로 설정합니다.
🔹 3. 퀘스트 상태 저장 (leaderstats 활용)
플레이어별 퀘스트 진행 상황을 저장해야 합니다. 이를 위해 leaderstats를 사용해 간단히 상태 변수를 만들어보겠습니다.
ServerScriptService 안에 Script 추가 후 아래 코드 입력:
-- ServerScriptService 안에 Script
game.Players.PlayerAdded:Connect(function(player)
-- leaderstats 생성
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- 퀘스트 상태 (0 = 미수락, 1 = 진행 중, 2 = 완료)
local questStatus = Instance.new("IntValue")
questStatus.Name = "QuestStatus"
questStatus.Value = 0
questStatus.Parent = leaderstats
-- 아이템 보유 여부 (0 = 없음, 1 = 있음)
local hasApple = Instance.new("IntValue")
hasApple.Name = "HasApple"
hasApple.Value = 0
hasApple.Parent = leaderstats
end)
🔹 4. NPC 대화 스크립트
QuestNPC 안에 ClickDetector 추가 → 그 안에 Script 삽입
-- QuestNPC 안의 Script
local npc = script.Parent
local clickDetector = npc:WaitForChild("ClickDetector")
clickDetector.MouseClick:Connect(function(player)
local questStatus = player.leaderstats.QuestStatus
local hasApple = player.leaderstats.HasApple
if questStatus.Value == 0 then
-- 퀘스트 미수락 상태
player.PlayerGui.ScreenGui.QuestLabel.Text = "안녕! 사과 하나만 가져다줄래?"
player.PlayerGui.ScreenGui.AcceptButton.Visible = true
player.PlayerGui.ScreenGui.AcceptButton.MouseButton1Click:Connect(function()
questStatus.Value = 1
player.PlayerGui.ScreenGui.QuestLabel.Text = "사과를 구해오세요 🍎"
player.PlayerGui.ScreenGui.AcceptButton.Visible = false
end)
elseif questStatus.Value == 1 then
-- 퀘스트 진행 중
if hasApple.Value == 1 then
questStatus.Value = 2
hasApple.Value = 0
player.PlayerGui.ScreenGui.QuestLabel.Text = "고마워! 보상으로 100 코인을 줄게 🎁"
-- 보상 코인 지급
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 100
coins.Parent = player.leaderstats
else
player.PlayerGui.ScreenGui.QuestLabel.Text = "아직 사과를 못 구했군요 🍎"
end
elseif questStatus.Value == 2 then
-- 퀘스트 완료 후
player.PlayerGui.ScreenGui.QuestLabel.Text = "이미 사과를 가져다줬잖아! 고마워 😁"
end
end)
🔹 5. 아이템(사과) 스크립트
Apple 파트 안에 Script 삽입
-- Apple 안의 Script
local apple = script.Parent
apple.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player:FindFirstChild("leaderstats") then
local hasApple = player.leaderstats.HasApple
if hasApple.Value == 0 then
hasApple.Value = 1
apple:Destroy() -- 사과 아이템 삭제
end
end
end)
🔹 6. 실행 흐름 정리
- 플레이어 → NPC 클릭 → 퀘스트 수락
- 맵 어딘가에서 사과 획득
- NPC에게 돌아와 대화 → 보상 지급
- 퀘스트 상태가 완료로 변경되어 다시 수락 불가
🎯 마무리
이렇게 하면 아주 기초적인 **퀘스트 시스템(아이템 수집 → NPC 전달)**을 완성할 수 있습니다.
- leaderstats로 플레이어 상태 관리
- ClickDetector로 NPC 상호작용
- Touched 이벤트로 아이템 수집 처리
- GUI로 대화창 연출
이 기초 시스템을 기반으로, 이후에는 여러 아이템 수집, 퀘스트 체인, NPC 대사 다양화 같은 기능을 추가하여 확장할 수 있습니다.🚀
'로블록스 게임 개발' 카테고리의 다른 글
| 로블록스 Task 라이브러리 (0) | 2025.09.20 |
|---|---|
| 로블록스 모듈 스크립트 (1) | 2025.09.19 |
| 로블록스 기본 GUI 버튼 제작 (예: "게임 시작" 버튼) (0) | 2025.09.18 |
| 로블록스 기본 파트 조립 및 Anchor, Collision, Transparency 등 속성 이해 (0) | 2025.09.18 |
| 로블록스 체력 0 되는 장애물 만들기 (0) | 2025.09.18 |