Difference between findfirstchild, getservice and just .thing

What’s the difference between using game.ServerStorage and game:GetService("ServerStorage")?
Are there drawbacks/problems/one better than the other?
Same with objects (this is excluding waitforchild because i know its purpose)
What’s the difference between ReplicatedStorage.Event and ReplicatedStorage:FindFirstChild("Event").
[The event was added using the game explorer.]

So game:GetService() fetches the specific service, and game.workspace is just finding a thing in the game. If you renamed workspace (possible), game:GetService(“workspace”) would work, and game.workspace, would not. Which is why if you’re randomly renaming everything in the game, game:GetService(“Thing”) is good, so you can find stuff without referencing the name.

Straight up indexing game with ServerStorage to find the service if it doesn’t exist (it’s not loaded in yet or the name is changed), an error will occur; However, using game:GetService("ServerStorage") will instantiate the service if it hadn’t been already and will obtain the service regardless of whether or not it has kept its original name. It’s better to use GetService anytime you’re grabbing a service.

With the second question, indexing Event with ReplicatedStorage to find “Event” in the service will error if it doesn’t exist, however FindFirstChild will return the object if it found it, or nil if it doesn’t exist which can be used as a prevention for your game breaking

2 Likes

Some cases people might use FindFirstChild because the object’s name is just a number or because using the normal .Thing would error if it doesn’t exist.

:GetService finds a service by it’s default name (or classname but i dont know).

For example if you change Workspace name then game.Workspace wouldn’t work but game:GetService('Workspace') would or another example is that RunService’s name is actually ‘Run Service’ so game.RunService wouldn’t work unless you do GetService or game['Run Service'] and sometimes services don’t load right away.

Will I actually get errors using game.service over getservice? I’ve noticed some unresponsiveness but not sure if it’s connected or not.

Errors caused by game.ServerStorage can happen if the service hasn’t been loaded yet or the name has been changed, but GetService won’t return any errors as if the service doesn’t exist, it’ll be created and returns the service regardless of the name not being its original name, unless you use an invalid service name in the function but studio’s code editor will warn you if you provide an invalid service name but if it’s not corrected, an error will occur

1 Like