I’m a bit unsure of how to do dialogue systems, because I don’t know if there’s a specific method I can do. Is there? I tried using a few dialogue plugins, but I want to make my own dialogue system rather than use one someone else made.
What I’m confused about is how I’d go about doing the npc prompt something depending on what answer you choose.
I kind of don’t want the dialogue system to be exploitable either, because if it’s exploitable players can abuse it to gain from it. I think avoiding client scripts completely is the best way to go for a dialogue system.
Roblox has an inbuilt one if you want to use it. It’s a game instance called Dialog and you can add dialog options by adding children to it called DialogOption.
For anything more than a simple yes/no question, this would most likely be a recursive function going through a table of nested questions/responses. Here’s an example:
local dialogue_path = {
question = "Hello, sir/ma'am. Would you be interested in a QUEST?";
answers = {
["For what reward?"] = {
question = "Why, only the best gold in all of the land! One-hundred Gold Coins to be exact.";
answers = {
["What is this, \"quest?\""] = { ... }; -- intense Shrek reference
["Maybe later."] = { ... };
};
};
["No."] = close_prompt; -- example callback function
};
}
it’d be a good idea to put this all in a module, since this table can get pretty big with even a simple conversation
Then, just define a function that goes through this table recursively.
local function next_dialogue(current)
current = current or dialogue_path
remove_buttons() -- remove buttons from last iteration (if any)
display_question(current.question) -- display the question on our imaginary screen
for i, v in pairs(current.answers) do
local btn = display_button(i)
btn.MouseButton1Click:Connect(function()
if type(v) == "table" then
next_dialogue(v)
elseif type(v) == "function" then
v()
end
end)
end
end
I think you get the idea.
I’m assuming you know how the rest works and you just need the logic itself. If you’re a complete beginner then you shouldn’t be making a system like this right away.