Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to use a module script to play dialog?

So i have an text value in RepStorage that updates the ui i also have a script in serverScriptService that changes the dialog i wanted to use a module script to change the text

i could not figure out to do it but heres my attampt

ServerScript

local RepStorage = game:GetService("ReplicatedStorage")
local DialogModule = require(script.DialogModule)

local TextValue = RepStorage:WaitForChild("Text")

TextValue.Value = DialogModule.Dialog[1]
wait(3)
TextValue.Value = DialogModule.Dialog[2]

Module Script

local DialogModule = {}
local Dialog = {
	"Hello and welcome to the expirment",
	"We will be asking some questions to see if youre a good test subject",
	"Question 1 : What is your name?"

}

local CorrectName = {

	"Alright thank you"
	-- Enterd name -- "Thats Correct?"
}

local Wrongname = {
	"Why are u lying to me",
	"Take him away"
}

local Dialog2 = {
	"Alright Second Question",
	"Are u scared?"
}

local Question2Yes = {
	"Dont Worry u dont have to be",
}

local Question2No = {
	"Well u should be",
}

local Dialog3 = {
	"Question 3 : Do u know where you are?"
}

local Question3Yes = {

	"Not a valid answer let me ask you again"
}

local Question3No = {
	"Alright",
	"You seem to be a valid test subject please follow me"
}
return DialogModule

1 answer

That's a good try, however, you're returning the variable called DialogModule, which is empty. What you could do is save the dialogs array in a dictionary, like this.

local DialogModule  = {
	["Dialog 1"] = {
		"Hey there!",
		["Sub dialog"] = {
			"Heeellooo"
		}
	},
	["CorrectName"] = {
		
	},
	["WrongName"] = {
		
	}
}

return DialogModule

Then, when you require the module, it will give you the dict with the dialogs, and you can access them by:

local DialogModule = require(path.to.module)

print(DialogModule["Dialog 1"])

Hope it helps u!

2 comments

0

but if i wanted to put more dialog in 1 table how would i do this?

0

I edited my answer, look Dialog 1, you can do that as many time as you want, you access them by: DialogModule["Dialog 1"]["Sub dialog"].

This discussion is preserved as it was. New answers, comments, and votes are closed.