I have a module script that creates a “secret” key
local secretkey = string.sub(tostring(game.Players.LocalPlayer.UserId), 1, 3).."HairSter"
return secretkey
when i grab the secret key, and print it, it prints this instead function: 0xe906b945c16bf9ce. Note that the thing that comes after the "function: " changes every time i relaunch the game. Is this a me problem or…?
This is likely happening because you are returning the code for the function instead of the actual result of the function.
You can change it by adding parentheses after the function call to evaluate the result of the function.
local function createSecretKey()
local secretkey = (string.sub(tostring(game.Players.LocalPlayer.UserId), 1, 3).."HairSter")
return secretkey
end
local result = createSecretKey()
print(result)
In this way, when you call the function and print the result, you should get the desired string value instead of the code.
function module:generateCode(strk)
local secretkey = string.sub(tostring(game.Players.LocalPlayer.UserId), 1, 3).."HairSter"
local questions = {
[1] = {
Question = "Please enter the access code.";
Solutions = secretkey;
};
[2] = {
Question = "h";
Solution = "hi";
};
}
local thequestion = questions[strk]
local enc = thequestion.Question
local sol = tostring(thequestion.Solutions).lower
return enc, sol
end
local enc, code
local function getProblem(s)
enc, code = themodule:generateCode(s)
textlabel.Text = enc
end
getProblem(1)
print(enc) --prints the right thing
print(code) --prints "function: some random series of characters"
The issue is that you are using the .lower method of the string, but you are not actually calling it. To call the method, you need to add parentheses after .lower .
I think this should work:
local module = {}
function module:generateCode(strk)
local secretkey = string.sub(tostring(game.Players.LocalPlayer.UserId), 1, 3).."HairSter"
local questions = {
[1] = {
Question = "Please enter the access code.";
Solutions = secretkey;
};
[2] = {
Question = "h";
Solution = "hi";
};
}
local thequestion = questions[strk]
local enc = thequestion.Question
local sol = tostring(thequestion.Solutions):lower()
return enc, sol
end
local enc, code
local function getProblem(s)
enc, code = module:generateCode(s)
textlabel.Text = enc
end
getProblem(1)
print(enc)
print(code)