Which way is more efficient?

which way is better to get to ReplicatedStorage and why

local RP = game:GetService("ReplicatedStorage") -- 1
local RP = game.ReplicatedStorage -- 2
2 Likes

I think they’re pretty much the same, but might be better to use GetService to get services like MarketplaceService, TeleportService, TweenService, etc.

2 Likes

Second option will be slightly faster but the difference is negligible.

task.wait(1)
local T1 = os.clock()
local RP1 = game:GetService("ReplicatedStorage")
local T2 = os.clock()
local RP2 = game.ReplicatedStorage
local T3 = os.clock()
print(T2 - T1)
print(T3 - T2)

image

1 Like

Developers can change the name of services, while GetService does a class lookup.

(read the replies in the thread I added above, they cover the advantages of GetService perfectly.)

1 Like

The dot operator is faster. That said- GetService is safer. By grabbing a service directly through that method you are ensured to reach the said service. If it doesn’t exist yet it will be created.

2 Likes

Well, to use the first option, it also looks better xd