Module script always returning nil

im trying to achieve a :wait() with argument module, the :WaitForProperty() is fine but there’s something wrong with this

function waitwithargument:WaitForEvent(event)
	event:Connect(function(arg1,arg2,arg3,arg4,arg5)
		if tostring(arg1) == nil then
			return "no argument was detected. (nil)"
		elseif arg2 == nil then
			return arg1
		elseif arg3 == nil then
			return arg1,arg2
		elseif arg4 == nil then
			return arg1,arg2,arg3
		elseif arg5 == nil then
			return arg1,arg2,arg3,arg4
		else
			return arg1,arg2,arg3,arg4,arg5
		end
	end)
	event:Wait()
end

it will always return nil, also heres the script calling the module

local prime = require(game.Workspace.prime7)
game.Players.PlayerAdded:Connect(function(plr)
local args,arg2 = prime:WaitForEvent(plr.Chatted)
print(args,arg2)
end)

what happens


expected output :
no

This is insanely horrible practice. Just do it in the main script instead.

So what happens is that the returns are returning to the event connection, not to the script calling WaitForEvent. The fix here is pretty simple, alll of this can be done in a single line.

function waitwitharguments:WaitForEvent(event)
    return event:Wait() -- this will return 1, 2, 3, 4, etc arguments depending on how many arguments the event provides.
end

At this point though, as much as I love modules, this almost just seems shorter to put in the main script. Do with it what you want of course.

I’m working on a module that simplifies your code

It adds arguments to :Wait() even if this is bad practice, can u fix it

But I want to add arguments to that :Wait(), that’s basically what my module does

When I implemented it it will always return nil

How do you mean add arguments to it? What is there to add?

For example you will normally do event:Connect(function(arg)

So my module will do that just with wait

Edit:oof, didn’t read code fully I’ll try it

it worked but one issue


the 2nd argument returned nil, the script code and the module code

module :

function waitwithargument:WaitForEvent(event)
return event:Wait()
end

script:

local prime = require(game.Workspace.prime7)
game.Players.PlayerAdded:Connect(function(plr)
local args,arg2 = prime:WaitForEvent(plr.Chatted)
print(args,arg2)
end)

Does it ever return something that is not nil though for the second argument?

Deprecated. For whisper messages, this was the Player who was the intended target of the chat message.

ohhhhh okay thanks tho here the solution