Intermediate Lua Scripting Tutorial

I have found many posts catering to beginners with Lua, but not many helping people improve their knowledge of Lua after they’ve got started. Hopefully I can address this issue today with this blog post, and give you all a few new things to work with, and improve your scripts.


Datastores are by far the best way of storing persistent data such as score, or items in their inventory. Some games I’ve played, they use datastores to save models and art – so it depends on use case. To get started with datastores, you will need to get the service from the game. To do this, use “game:GetService(var)” where “var” is the string of the service name – it will return the service which means you can call functions which reference the service, or store it in a variable like so: “local DatastoreService = game:GetService(“DatastoreService)”.

Now you may want to get a specific datastore by calling DatastoreService, so to do this you need to use a member function called “GetDataStore”. This function is able to take two arguments, one is the string and the other is the name of the scope of the assigned datastore. Scope becomes relevant when your game has multiple worlds in it. The scope can be a good thing if you have multiple datastores for a single player, for example Resources or Score. You would make the scope the players unique ID so it doesn’t get referenced by other players ingame – as it’s unique to that single individual. Scope is an optional argument, so you only need a minimum of one argument in order to use “GetDataStore”.

You can use “local Datastore = DatastoreService:GetDataStore(“score”)” which will load the datastore “score” in the global scope, which means it can be used by any function now referenced without having to call that same datastore.

Datastore Example Roblox

CRframe Basics

I’m still in the beginner stages with CFrame, however I find writing blog posts helps me digest information. I still have knowledge I can share with you, so I’ll go ahead and spill the beans on everything I know here. CFrames are much more powerful and versitile than vectors, as they both store location/rotation as well as unit vectors with the direction of each face – which is useful for instance to make a section of an object move forwards, all you have to do is multiply CFrame by the new CFrame made by Vector3 of its LookVector. CFrames also make methods for rotations available, as you have Euler Angles which are the relative axis of the selected part. This means you can easily rotate a section around it’s positioned axis which is better than rotating on absoloute axis.