What does the syntax function foo():bar mean?

Exactly what the title says.
What does the syntax function foo():bar mean?
I saw it on a post where it looked like this:

I’m thinking it means the type of object it returns, but I haven’t confirmed this.

:Method takes a classname and I guess it’s saying that “Hey this function is a Vector2 function”, from what it looks like.
I’m not familiar with this these new roblox Lua methods. Maybe someone else can explain

1 Like

Yes, but it was used in this context:
local pos = getPos()
And not like a Method

Never seen it, didn’t even know this exited because it doesn’t in vanilla lua, so this is something Roblox themselves implemented.
Why they did so is still a mystery as it doesn’t seem to have any valid uses for it.

You can’t define Vector2 inside the function or outside, it doesn’t do anything.

1 Like

Is that it? It doesn’t do anything?

Well yeah, I see no use for this?

1 Like

Feels like it’s the same as doing local Test: BasePart = workspace.BasePart

1 Like

It’s just to define what it is from my understanding, like the comment above I posted.

1 Like

I actually think the syntax would be something like this:

local function CreatePart():Part
    return Instance.new(“Part”)
end
local Part = CreatePart()

And now the Lua autofill knows that the Partvariable is a Part, and can give suggestions like :Destroy() etc…

Yes, that’s what I believe …….

Mhm yeah, it’s just to tell the programmer what the function does etc, is what I would say it is, and what the purpose of it is (part-related etc)

1 Like

Yup, sure seems like this is the true intention behind it, just like the variables.

1 Like

Not entirely, since if you use the syntax

local Part: BasePart = workspace.Part

Then the Lua autofill knows its a part and can give specific suggestions

local function Test(Test1 : Player, Test2 : Vector2)
end

But then again you have another way of doing it.

1 Like

Can’t confirm the autocomplete, haven’t tested this yet

1 Like

If I were to try it, I would do something like this:

function Test():Decal
    return Instance.new(“Part”)
end

And see if using the function returns a variable that has the Decal’s autofill (such as .Image) but actually returns a part.

Both methods is fine, but I guess function Do():ClassName is used if you aren’t using any arguments inside it.

Edit
*Can be used if you aren’t using any arguments.

1 Like

That’s the return type, it states what type the function would give back. It basically makes it easier to use types since x would automatically be assigned the type Vector2:

function getPos():Vector2
	local pos = workspace.CurrentCamera:WorldToScreenPoint(MS.Hit.Position)
	return Vector2.new(pos.X,pos.Y)
end

local x = getPos() -- Autoassigned Vector2 type
1 Like

It will return whatever you return though.

I knew it! Thanks for clarifying!

It was only because I tried finding documentation and found nothing