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

String Inside Module not working?

Hello there! I have a ModuleScript with this simple code:

local string = {"MyString1","MyString2"}

then I have a normal script that checks a textbox for the text:

local module = script.ModuleScript
local string = module.string
if script.Parent.text == string then
print("YOU GUESSED RIGHT!")

2 comments

0

You need to return string at your module, and require it in another scirpt

0

I've typed return string and tried the require but not to sure what to do, are you able to fix the script?

1 answer

✓ Accepted answer

string is a table, not a string, overrides the built-in table by the same name, and isn't part of the module. You've declared it in the scope of the script rather than part of the module in this case, and as Incapaxx has said, you also need to require it in order to load it.

Firstly, in order to load it up, use the reference to the module as the sole argument in the require function and save its return value, which would look like this:

local module = require(script.ModuleScript)

Now the module will actually be loaded. Next, you'll want to make the string part of the module instead of local to the script, compare the guess to a value inside the table, and change its name so you're not overriding the built-in string table.

I'm not sure why you have multiple strings has the correct answer, but I'll assume it's because you want multiple correct answers. In this case, the table should be turned into a dictionary, with the correct answers being stored as keys, and the values being true.

module.correctStrings = {MyString1 = true, MyString2 = true}

Now, instead of comparing the guessed string to the correct string, you'll want to use the guessed string as a key to index the correctStrings table and see if it indexes true.

local correctStrings = module.correctStrings
if correctStrings[script.Parent.Text] then
	--A correct string has been guessed.
end

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