What's the best way to get the Workspace?

Hi there. :hidere:

I have been getting the workspace by typing “game.workspace” for quite long ago, then I realized you can just type in “workspace” instead so I then started using it.

I’m just wondering: what’s the most optimized way / best way there to get the Workspace?
Is there something wrong with getting the Workspace by:

--using
workspace

--instead of...
game.workspace

--or (I don't even use this one)
game:GetService("Workspace")

I always thought typing “workspace” was a good practice since it’s more compact and also less text means cleaner code, but is it really the best option there?

Please, let me know what you think down below. Thanks for your help. :tongue:

4 Likes

I’ve ran a performance test in Studio on workspace, there’s little to no performance difference between game.Workspace and workspace.

Edit: game:GetService('Workspace') runs pretty much at the same speed as workspace.

17 Likes

there’s no point in this;
indexing workspace is just as simple as doing game.Workspace or workspace simply, it’s loaded implicitly almost as immediately as a player joins, it won’t affect performance (or at least not significantly enough)

2 Likes

Good question.

When I began scripting, I used tutorials, some people used workspace, some people used game.Workspace. I thought game.Workspace was more advanced, but turns out no difference!

2 Likes

It says here the difference between workspace, game.Workspace and game:GetService(“Workspace”).

3 Likes

Thanks for all your feedback! :wink:
I will just stick to use workspace to keep my code smaller.

2 Likes

I never knew you could use “workspace” instead of game.Workspace or game:GetService(“Workspace”)
I’ve only saw it in 1 script, but thought it was a mistake
Well, thanks for the info

1 Like