Hello fellow developers! I have a question I need some answers on… QUESTS! I know this has already been posted many many times but I’ve read through the posted ones and none have answered my questions specifically. So, I’ll be listing them down here!
I am in a midst of making a quest system similar to the one in Bee Swarm simulator. I have the dialogues ready but I have encountered some problems with the quest giving, processing and rewarding.
-
After a player gets a quest, how can I keep track that the player has finished/ not finished the quest? For example, Collect 5 Apples, I thought of doing a check to see if the player has >5 apples then he/she gets rewarded but then I realised that that won’t work if the player already has 10 apples, or anything more than 5. The quest would be completed instantly. So, how do I track that a player has collected the certain amount required no matter how much of the item the player already has collected before?
-
Giving quests. I am able to give a quest if its just 1. But I do not know how to give it in progression, like Quest 1 then Quest 2 then Quest 3, and also how would I give out quests in random order? Like once the player talks to the NPC he/she gets Quest 10, then completes it and talks to the NPC again and now gets Quest 3?
-
How do daily quests work? I’ve tried to wrap my head around os.time for quite some time and I always cannot do something successful with it.
-
Lastly, how do I prevent a player from taking another quest if the player already has taken a quest from that same NPC?
I will be providing some of the tries I did trying to resolve these issues. (Problems 1,2 and 4 only)
Code for Problem 1: (Tracking Quests)
local Players = game:GetService("Players") -- My attempt at tracking quests
local Player = Players.LocalPlayer
local QuestModule = require(game.ReplicatedStorage.Modules.QuestModule)
local Apple = Player:WaitForChild("Stats"):WaitForChild("Apple")
local QuestLabel = script.Parent.Bar.AmountText
local QuestProgress = script.Parent.Bar.AmountNeeded
local onAppleChanged
onAppleChanged = Apple:GetPropertyChangedSignal("Value"):Connect(function()
if Apple.Value < 200 then
QuestLabel.Text = "Collect 200 Apples"
else
QuestLabel.Text = "Collect 200 Apples completed!"
local QuestComplete = game.ReplicatedStorage.Remotes.QuestComplete
QuestComplete:FireServer("RewardToGive")
end
end)
Code for Problem 2: (Giving Quests)
QuestServer.OnServerEvent:Connect(function(Player, State)
if State == "Quest1" then -- My attempt at giving a single quest
print("Success!")
local OneTaskQuest = script.QuestTemplateOne:Clone()
OneTaskQuest.Parent = Player:WaitForChild("PlayerGui"):WaitForChild("UIs").QuestFrame.ActualFrame.Frames.ConcurrentQuestFrame
Player:FindFirstChild("Mage").Value = "Quest1Taken"
game.Workspace.Quest1.Mage.ProximityPrompt.Enabled = true
end
if State == "RandomQuest" then -- My attempt at giving random quests
for i,v in pairs(script.RQuests:GetChildren()) do
local Number = math.random(1,3)
wait()
if Number == 1 then
if v:FindFirstChild("Type").Value == "1" then
local OneTaskQuest = v:Clone()
OneTaskQuest.Parent = Player:WaitForChild("PlayerGui"):WaitForChild("UIs").QuestFrame.ActualFrame.Frames.ConcurrentQuestFrame
OneTaskQuest.Visible = true
end
elseif Number == 2 then
if v:FindFirstChild("Type").Value == "2" then
local OneTaskQuest = v:Clone()
OneTaskQuest.Parent = Player:WaitForChild("PlayerGui"):WaitForChild("UIs").QuestFrame.ActualFrame.Frames.ConcurrentQuestFrame
OneTaskQuest.Visible = true
end
elseif Number == 3 then
if v:FindFirstChild("Type").Value == "3" then
local OneTaskQuest = v:Clone()
OneTaskQuest.Parent = Player:WaitForChild("PlayerGui"):WaitForChild("UIs").QuestFrame.ActualFrame.Frames.ConcurrentQuestFrame
OneTaskQuest.Visible = true
end
end
end
end
end)
Code for Problem 4: (Preventing Players from taking quests repeatedly)
local Debris = game:GetService("Debris")
local ProximityPrompts = script["Proximity Prompts"]
local Settings = script.Settings
local proximityPrompts = {}
local connections = {}
local screenGuis = Settings.ScreenGuis:GetChildren()
local timeUntilDelete = Settings.Time.Value
local function getProximityPrompts()
for index, child in pairs(ProximityPrompts:GetChildren()) do
if child:IsA("ObjectValue") then
local prompt = child.Value
if prompt:IsA("ProximityPrompt") then
table.insert(proximityPrompts, prompt)
end
end
end
end
local function onTriggered(player)
local playerGui = player:WaitForChild("PlayerGui")
if not playerGui then return end
if player:FindFirstChild("Mage").Value == "Quest1" then
script.Parent.Trevor.ProximityPrompt.Enabled = false -- my attempt on preventing repeated quests
print("Newcomer!")
for index, screen in pairs(screenGuis) do
for index, child in pairs(playerGui:GetChildren()) do
local childCloneSource = child:FindFirstChild("CloneSource")
if childCloneSource then
if childCloneSource.Value == screen then
child:Destroy()
end
end
end
local newScreen = screen:Clone()
local cloneSource = Instance.new("ObjectValue")
cloneSource.Name = "CloneSource"
cloneSource.Value = screen
cloneSource.Parent = newScreen
newScreen.Parent = playerGui
--Debris:AddItem(newScreen, timeUntilDelete)
end
elseif player:FindFirstChild("Mage").Value == "Quest1Taken" then -- my attempt on preventing repeated quests
print("Already taken!")
if player:WaitForChild("PlayerGui"):WaitForChild("UIs").QuestFrame.ActualFrame.Frames.ConcurrentQuestFrame:FindFirstChild("QuestTemplateOne"):FindFirstChild("Completed").Value == false then
print("Complete first!")
else
player:FindFirstChild("Mage").Value = "Quest2" -- giving player next quest
print("Congrats!")
player:WaitForChild("PlayerGui"):WaitForChild("UIs").QuestFrame.ActualFrame.Frames.ConcurrentQuestFrame:FindFirstChild("QuestTemplateOne"):Destroy()
end
end
-- Code --
getProximityPrompts()
for index, prompt in ipairs(proximityPrompts) do
local connection = prompt.Triggered:Connect(onTriggered)
table.insert(connections, connection)
end
I really really hope I can get the problems resolved with your help. Thank you ALL!
~ I also have another post I need help on a Boosting/Bonus system you can check out!