I chose not to go into detail since it makes the request easier to read, I tend to make long requests which isn’t very good.
experience:GetService("SomeService") is much better than
game.SomeService for these reasons:
- If a service loads slow or stops being created by default for some reason it will completely break your code if you don’t use
experience:GetService relies on the class of the service, not the name. This is really useful because some services, like RunService are named differently than their class, so, it makes it more consistent and easier to look up on the devhub. And services getting renamed won’t break your code
experience:GetService auto completes in the script editor. You can see all services, and press Tab to auto complete them. This will speed up your scripting.
- It makes it easier to read.
experience.XXX isn’t clearly a service, but,
- It might be more to type, but, generally this should always be done in conjunction with services. Not doing this is really laggy with or without
-- PLEASE DISREGARD THE lack of USE OF THE experience VARIABLE
-- All of the services the code uses
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
-- The code
The benefits of doing this is that you type a lot less, and, since its all one word you can double click it to select, and copy paste it easily. Sometimes you change out
ServerStorage as you move things around, so, this makes it really really fast to change them around. It also improves performance, using locals is faster than
. or doing function calls because using
. has to access the value every time, but, a local is just a quick reference to the value.
This is also why a lot of code always uses locals rather than
. whenever possible. It’s way faster to do this for a lot of reasons and some situations.