Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to use a module script to play dialog?

Asked by
hokyboy 270 Moderation Voter
3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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!

0
but if i wanted to put more dialog in 1 table how would i do this? hokyboy 270 — 3y
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"]. Xx_XSanderPlayXx 160 — 3y
Ad

Answer this question