How would I return a value or a table of functions

So It’s kinda hard to explain but I’ll try my best

So take Vector3 for example:

Vector3.new(0, 0, 0)

That returns just a Vector3 object. However if you do

Vector3.new(0, 0, 0):

It returns a table of functions.

So how would I do that? It’s probably simple and I’m just missing something.

A : is used for method access of an object. To see what this means I’ll lay out a hypothetical Vector3 definition:

local Vector3 = {}
Vector3.__index = Vector3

function Vector3.new(x, y, z)
    local new = {}
    new.X = x
    new.Y = y
    new.Z = z
    return setmetatable(new, Vector3)
end

function Vector3:Dot(other)
    return self.X * other.X + self.Y * other.Y + self.Z * other.Z
end

The use of the : in the Dot definition injects the self variable into the code for you to use. An equivalent definition could be

function Vector3.Dot(self, other)
    return self.X * other.X + self.Y * other.Y + self.Z * other.Z
end

Similarly you can access the Dot function either using “:” or “.

local vector = Vector3.new()
local other = Vector3.new()

--  Using . to access Dot
vector.Dot(vector, other)

-- Using : to access Dot
vector:Dot(other)

This Isn’t exactly what I was talking about. I know about the difference between colons and dots.
My question was Vector3.new() returning a vector3 and Vector3.new():Function()
E.G: Vector3.new():Lerp() or Vector3.new():Dot().

My only idea, which doesn’t work, is returning a table of functions like:

local T = {}

function T:Something()
    -- Do stuff
end

return T

However that does just that. Returns a table. If i wanted to get something using .new on one of my functions, it would return that.

That’s the issue. I want to return the value if you don’t use any : or . on it. And return a list of functions If I do call on it like that.

The code I gave in the previous reply would support this Vector3.new():Function() behaviour, perhaps you should try and understand how it works.

I think it is easier to understand by breaking it down so that it is not just one line of code. E.g.

-- Before:
local result = Vector3.new():Function()

-- After:
local vector = Vector3.new()
local result = vector:Function()

Hopefully this will make it clearer. You can think of the vector instance as being a table of data and functions.