Functions using two parameters with the same name?

Hey guys, so I’ve been learning about Metatables recently, and I’ve understood everything just fine until now. I noticed that in a tutorial I saw, two parameters of the same name were put into a function, and were divided by a colon instead of a comma. I have never seen anything like this before, and I can’t seem to figure out what it’s used for. Any help would be appreciated!

EX:

function Module.new(Player : Player)

end

This is for use in Roblox’s type checker. It means that the thread will error if the parameters provided is not a player. You can do similar things with other types as well.

2 Likes

That’s only one argument, it’s just using Luau typechecking syntax which allows you to assign a type to a variable.

For example, defining a function like this would only actually take 2 parameters: actualArgument1, which should be a player, and actualArgument2 which should be a CFrame.

local function doSomething(actualArgument1: Player, actualArgument2: CFrame)

If you want to learn how to use Luau type checking, you can check out the docs:

This is a good tutorial for beginners as well:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.