Passing nameless arguments

I’m trying to pass an event to the client that will run a function on the client with the argument func that refers to the name of the function I wanna call and ... being optional arguments.

Server:

remotes.InvokeClient:FireAllClients("PrintMsg", "Hi! I'm working")

Client:

remotes.InvokeClient.OnClientEvent:Connect(function(func, ...)
	MainHandler[func](...) -- the function is being called but 'nil' is received as an arg
end)

Any ideas why this may not work? Tried searching for a while but I couldn’t find anything that could help me. Thanks.

What is MainHandler? If it’s not a table, it won’t work.

It’s a module

For reference:

function MainHandler:PrintMsg(msg)
	print(msg)
end

Just to be clear, is it erroring? If it is, what is the error?

There’s no error

When debugging and printing the argument msg, it just spits out nil

Oh, this is because of how the colon works.
Basically:

function foo.Bar(object, s)

end
function foo:Bar(s) -- object is automatically being passed in when called with the : 

end

So basically, when you call the function like that in the main script, it acts like the dot function, resulting in msg being nil. So replace the colon with a dot.

1 Like

Life saver, thanks. Just had a little bit of confusion.