Putting a underscore before function names?

Hello, I was watching a roblox developer on youtube and I noticed for their functions they always put a _ before them?

e.g.

function _getPlayerMoney()
end

I was wondering, is this just for aesthetic purposes or is it an actual convention?

The video: Roblox Holiday Dev Vlog *GIFTING SYSTEM* - YouTube

1 Like

It’s probably just a personal thing. I haven’t seen this ever, so I wouldn’t do it. I would just follow either the PascalCase or camelCase naming conventions.

“_” is allowed in variables, some think it looks better

EDIT: they are important when using metatables

1 Like

Usually, underscores at the very beginning indicate that the method / variable is supposed to be private (because we don’t have a full-proof “private” visibility modifier in Lua). I would suggest prefixing only using one underscore, not two because the latter is what metamethods use, so in case they add new ones, your function would be okay.

My personal naming conventions is _like_this because I like to keep things lowercase, so I give underscores higher priority than different casing.

2 Likes

Relevant read: Roblox Lua Style Guide - Naming

  • Prefix private members with an underscore, like _camelCase .
    • Lua does not have visibility rules, but using a character like an underscore helps make private access stand out.

Also relevant: Access modifiers

4 Likes