Usage of : and . With Functions


I was fiddling around with module scripts and remembered you could use : and . when using functions with module scripts. I know how : defines the module script as self and . does not, but when would this be useful?

If I’m misunderstanding anything, please point it out! It’s been a hot minute since I’ve scripted :))

Thank you!


It’s usually for when you make OOP since you don’t really have to define self yourself. But for indexed functions you need to define it yourself.

1 Like

Well I did figure it would be used for OOP, I probably should have said that. I kind of meant how would it be used more specifically? Like why would it be useful to reference the script that self represents?

: is just there so that self is implicitly defined. Otherwise, you’d have to do Class.Method(object, ...) every time. Whereas with the colon, you can simply do object:Method(...).

I mean, imagine having to do game.GetService(game, "service") dozens of times.

1 Like

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