My module isn't working

  1. What do you want to achieve?
    I want to achieve a system that encrypts data. What it does is it will keep scanning until it finds a match.

  2. What is the issue?
    It isn’t returning a value somehow.

  3. What solutions have you tried so far?
    Nothing helped.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

	local function decode()
		for i, char in pairs(newString) do
			newKey = string.gsub(key, char, alphabet[i])
		end
	end

	local function Choose()
		while wait(.001) do

			if table.find(newTable, key, 1) then

				return key
			elseif not table.find(newTable, key, 1) then
				decode()
			end
		end
	end

I don’t know why it doesn’t work

Is that your full module? You have to return a single value which is most commonly a table with your functions inside.

local module = {}
function module.decode()
    for i, char in pairs(newString) do
		newKey = string.gsub(key, char, alphabet[i])
	end
end
function module.Choose()
    while true do
        if table.find(newTable, key, 1) then
		    return key
		elseif not table.find(newTable, key, 1) then
			decode()
		end
        wait()
    end
end
return module

No, I just didn’t include the name or real table names. The code I showed is just the one module function that isn’t working.

Are you sure the function is even being called?
Using “local function” in a module script will allow it to be called only from the module script and not externally.
Hopefully this helps.

I have found the error. I messed up with the randomization.

EDIT: there was no error, but it wasn’t finding it because of how the randomization worked at the time.

Glad you found the fix, good luck!

Actually, somehow it isn’t returning the value i need