How would I make one NPC give Random Quest to Player

It my first time using a module script. I wanted to know how to make one npc give a random quest when a player clicks them.

Here what I got so for:

local module = {
	[1] = "";
}

function module.AddQuest(player)
	local Folder = Instance.new("Folder", player)
	Folder.Name = "QuestStuff"
	
	local QuestName = Instance.new("StringValue", Folder)
	QuestName.Name = "QuestName"
	
	local QuestDescription = Instance.new("StringValue", Folder)
	QuestDescription.Name = "QuestDescription"	
	
	local Amount = Instance.new("NumberValue", Folder)
	Amount.Name = "Amount"
end

function module.QuestInfo(player)
	
end

return module
1 Like

You’re on the right track here, actually. What exactly are you confused on?

The next thing I need to make is the player getting the quest info. The quest title, description, etc. How would I do that using the module script table and sending it to the server?

Instead of using

local module 

I would start with

local quests = 1 --- any number you want of quests.

I found doing this was much easier than what you were doing.

1 Like

Thank you, I was wondering how to do that. How would I have multiple values inside that table. For example I want the exp you gain for a mission. The name of the mission then the description of the mission after. Just an example.

You can have a separate module that outlines all your quests for easy editing.

In said module

local quests = {
    {
      NAME = "Talk to Merchant"
      EXP = 30,
      DESC = "Travel to the Farlands and talk to the Merchant!",
   },
   {
      -- repeat the same format so that your other module can read it!!
   },
   -- and so on...
}

return quests

Then in your “Quest Giving” module…

local questsList = require(path.to.the.quests.module)

function module.AddQuest (player)
   local randomQuest = questsList[math.random(1,#questsList)] -- now we have a random array from the last module we made
   
   local Folder = ...

   local QuestName = ...
   QuestName.Name = randomQuest["NAME"] -- or randomQuest.NAME (it's your preference for this)

   -- now imma let you fill in the other parts :)
end
1 Like