Games
Quest Systems
Luau
Source & Structure Checked (Roblox Luau)
Roblox Luau Quest & Objective Tracker
Typed Roblox Luau ModuleScript service for tracking per-player quest states, incrementing objective counters, and emitting completion rewards cleanly on the server.
Architecture & Runtime Preview
Roblox StudioRoblox Luau server module — store QuestConfig in ReplicatedStorage/Quests/QuestConfig and QuestService in ServerScriptService/Quests/QuestService.
- 1ReplicatedStorage/Quests/QuestConfig.luau (frozen quest + objective definitions)
- 2ServerScriptService/Quests/QuestService.luau requires QuestConfig via ReplicatedStorage:WaitForChild("Quests"):WaitForChild("QuestConfig")
- 3QuestService.AcceptQuest(userId, questId) & RecordProgress(userId, objectiveType, delta, onCompleted)
Example Project Integration: Place QuestConfig.luau as a ModuleScript at ReplicatedStorage/Quests/QuestConfig and QuestService.luau as a ModuleScript at ServerScriptService/Quests/QuestService.
Source Code (2 files)
--!strict
export type QuestReward = {
xp: number,
gold: number,
}
export type QuestDefinition = {
id: string,
title: string,
objectiveType: string,
targetCount: number,
reward: QuestReward,
}
local Quests: { [string]: QuestDefinition } = {
slime_hunt = {
id = "slime_hunt",
title = "Clear the Meadow",
objectiveType = "defeat_slime",
targetCount = 5,
reward = { xp = 120, gold = 50 },
},
herb_gather = {
id = "herb_gather",
title = "Alchemist's Request",
objectiveType = "collect_herb",
targetCount = 3,
reward = { xp = 80, gold = 35 },
},
}
return table.freeze(Quests)
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local QuestsFolder = ReplicatedStorage:WaitForChild("Quests")
local QuestConfig = require(QuestsFolder:WaitForChild("QuestConfig"))
export type PlayerQuestState = {
questId: string,
progress: number,
completed: boolean,
}
local QuestService = {}
local playerStates: { [number]: { [string]: PlayerQuestState } } = {}
function QuestService.AcceptQuest(userId: number, questId: string): boolean
local def = QuestConfig[questId]
if not def then
return false
end
playerStates[userId] = playerStates[userId] or {}
if playerStates[userId][questId] then
return false
end
playerStates[userId][questId] = {
questId = questId,
progress = 0,
completed = false,
}
return true
end
function QuestService.RecordProgress(
userId: number,
objectiveType: string,
delta: number,
onCompleted: ((userId: number, def: QuestConfig.QuestDefinition) -> ())?
): number
if delta <= 0 then
return 0
end
local active = playerStates[userId]
if not active then
return 0
end
local completedNow = 0
for questId, state in active do
if state.completed then
continue
end
local def = QuestConfig[questId]
if def and def.objectiveType == objectiveType then
state.progress = math.min(def.targetCount, state.progress + delta)
if state.progress >= def.targetCount then
state.completed = true
completedNow += 1
if onCompleted then
onCompleted(userId, def)
end
end
end
end
return completedNow
end
function QuestService.ClearPlayer(userId: number)
playerStates[userId] = nil
end
return QuestService
Installation & Usage
Create a Folder named Quests in ReplicatedStorage with ModuleScript QuestConfig (QuestConfig.luau), and a Folder named Quests in ServerScriptService with ModuleScript QuestService (QuestService.luau).
Require ServerScriptService.Quests.QuestService on the server, call QuestService.AcceptQuest(player.UserId, "slime_hunt"), and report progress via QuestService.RecordProgress(player.UserId, "defeat_slime", 1, onCompleted).