ModuleScript function returns nil

for some reason when i run my module function in remote event, it returns nil and not string. in any other script, it returns a string. idk how to fix this

local passwordgen = require(game.ReplicatedStorage:WaitForChild("Password Generator"))
local res = game:GetService("ReplicatedStorage")
game.ReplicatedStorage.Run.OnServerEvent:Connect(function(p)
	local d = game.Workspace["Password Generator"].digits.Value.Value
	local s = game.Workspace["Password Generator"].symbols.Value.Value
	local u = game.Workspace["Password Generator"].upper.Value.Value
	local l = game.Workspace["Password Generator"].lower.Value.Value
	local text = game.Workspace["Password Generator"]:FindFirstChild("password screen").SurfaceGui.TextLabel
	local password = passwordgen.Generator(10,d,s,u,l)
	print(password)
	text.Text = password
end)

can u show the module script pls?

1 Like
local passwordgen = {}

function passwordgen.Generator(length, digits, symbols, upper, lower)
	local tab = {}
	local pass = false
	local index = 0

if length <= 0 then return end
if digits == false and symbols == false and upper == false and lower == false then return end	

	
	local min = {}
	local max = {}
	local mins = {}
	local maxs = {}

	if digits == true then
		table.insert(min, 48)
		table.insert(max, 57)
	else end

	if symbols == true then
		table.insert(mins, 33)
		table.insert(mins, 35)
		table.insert(mins, 63)
		table.insert(maxs, 33)
		table.insert(maxs, 38)
		table.insert(maxs, 64)
	else end

	if upper == true then
		table.insert(min, 65)	
		table.insert(max, 90)
	else end

	if lower == true then
		table.insert(min, 97)
		table.insert(max, 122)
	else end

	while true do
		wait()
		local roll = math.random(1, #min + 1)
		index = index + 1
		if min[roll] == nil and symbols == true then
			local roll2 = math.random(1, #mins)
			table.insert(tab, index, math.random(mins[roll2], maxs[roll2]))
		else
			roll = math.random(1, #min)
			table.insert(tab, index, math.random(min[roll], max[roll]))
		end
		if index == length then
			break
		end
	end

	local password = string.char(tab[1])
	index = 1	

	repeat
		password = password .. string.char(tab[index + 1])
		index = index + 1
	until index == length

	return password
end


return passwordgen

local passwordgen = {}

This is probably the issue. I’m not experienced in OOP so I can’t tell you how to fix it but just giving a clue lol

1 Like

Are the passed variables boolean values or numbers?
Could you show what values you are inputting into the function, please?

1 Like

the values being input for length is a number value, the rest of the values (d,s,u,l) are boolean values from BoolValue’s

        local d = game.Workspace["Password Generator"].digits.Value.Value
	local s = game.Workspace["Password Generator"].symbols.Value.Value
	local u = game.Workspace["Password Generator"].upper.Value.Value
	local l = game.Workspace["Password Generator"].lower.Value.Value
	local password = passwordgen.Generator(10,d,s,u,l)
	print(password)
	text.Text = password
end)

ok i just realized that i forgot to pass on my d, s ,u, l values from the localscript into the FireEvent() function. So all my bool values were false and were returning nil on the string.