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)
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.
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)