SCRIPTING: Should I use the . prefix for function or the inbuilt function variable?

Hi! I am wondering this:

Should I use the . PREFIX for function variables OR the studio INBUILT function variable?
Most of the people (may be you too) wont understand what I mean by that, And here is an example:

local module = {}

return module

This is a basic module script, Now if I we’re to make a function, What way should I do?

Option 1: The basic way

local module = {}

function module.MyFunction()
	print("My function!")
end	

return module

OR

Option 2: The prefix

local module = {}

module.MyFunction = function()
	print("My function WITH . prefix!")
end

return module

Both options are the same (ATLEAST to my knowledge)
But I want YOUR opinions first.

1 Like

just readability and semantics, its completely subjective. i use both in various situations, but primarily option 1 because its more coherent with other modern languages.

1 Like

I prefer option 1


As per the Official Roblox Lua Style Guide, there are specific patterns you should follow when defining functions in modules or tables.

When declaring a function inside a table, you should use the function-prefix syntax. It is also important to differentiate between . and : to denote the intended calling convention.


:white_check_mark: GOOD

-- This function should be called as Frobulator.new()
function Frobulator.new()
    return {}
end

-- This function should be called as Frobulator:frob()
function Frobulator:frob()
    print("Frobbing", self)
end

:cross_mark: BAD

function Frobulator.garb(self)
    print("Frobbing", self)
end

Frobulator.jarp = function()
    return {}
end

:red_question_mark: Why does this matter?


So TL;DR – Option 1.

1 Like

These both behave the same, but you can use option 2 to set keys to any function, whether it be anonymous or defined (like print).

use number 2

Who cares.

No, like really. It’s the same thing. It’s like asking me if I should use ServerScriptStorage or ReplicatedStorage, like bro, it’s the same thing. My approach to making games is client-authoritative, where the client can directly control data and gameplay.

1 Like

I’m sorry but stating that the distinction between ServerScriptService and ReplicatedStorage doesn’t matter is factually incorrect and potentially harmful advice for new developers.

Why?


1. The Security Reality ServerScriptService is a secure vault; the client cannot see or access its contents. ReplicatedStorage is a public window; every line of code there is downloaded to the client’s memory. If you put sensitive logic in a replicated container, you are handing exploiters the instruction manual to your game.

2. The Danger of “Client-Authoritative” Design Suggesting a client-authoritative approach, where the client directly controls data, is how games get destroyed by exploiters. In a multiplayer environment, the Server must be the Source of Truth.

  • If the Client is the authority on “Gameplay,” they can teleport, auto-kill, and fly.
  • If the Client is the authority on “Data,” they can grant themselves infinite currency.

As for the OP


I highly suggest you stick with Option 1, while Luau technically processes both similarly, Option 1 is the Official Roblox Style Guide standard for several reasons:

  • Debugger Support: The Studio debugger and stack traces will explicitly name the function. Option 2 can sometimes show up as “anonymous function” in error logs, making debugging a nightmare.
  • IDE Tooling: The Script Analysis and “Go to Symbol” (Ctrl+Shift+O) features are optimized for the function Name() syntax.
  • Consistency: It allows you to switch between . and : (for OOP/self) seamlessly, whereas Option 2 requires manual, error-prone self arguments.

I can defend that you shouldn’t put ALL of your code/scripts inside replicated storage.
Because again, It makes the game easy to steal/copy the scripts and basically reupload the game but with slight changes,

Take forsaken for example, Basically all of their code/scripts ARE in replicated storage, So exploiters do what they do best, AKA to just copy all of the game assets and reupload the game but with changes