Find function in a module

hey, I want to be able to do this

Module [ Something ] ()

And if function in module isn’t found instead of erroring run this function

Module.Default()

1 Like

Can you show us your module script to see your problem?

1 Like

Not scripting right now, but (sry for bad text I’m on mobile xD)

This is what I have…

Module [ Something ] ()

But I want it so if this function isn’t In the module run another code

Do I need to use Metatables? Or something

Waa, why u deleted it? xD I was learning. I got ur idea, I think it could work!

Wrapping it around a pcall didn’t work BTW

I think __index is best suited for this, since it is invoked when you index for a nil value in a table.

local module = { Default = print }

setmetatable(module, { __index = function(_, key)
    return module.Default
end })

module.Something("hello world")

cc @Dev_Peashie (i wasnt happy with the first reply ;p)

3 Likes

Thought so lol thx I’ll use this tomorrow!