Getting Workspace

What’s the best option to get Workspace?

game:GetService("Workspace")
game.Workspace
workspace -- I'm using
1 Like

game:GetService("Workspace") is the best choice tbh

1 Like

Not really, workspace is the best because it is the shortest

1 Like

game:GetService("Workspace") and workspace are basically the same thing as they both reference the Workspace service

game.Workspace is risky to use as it’s indexing a child called Workspace, which means if you ever accidentally rename the workspace service, it will error. Using the other two ensures you get the service instead of something else as it does a ClassName look up

basically, use workspace, same as game:GetService("Workspace") but is shorter to write, but you can use game:GetService("Workspace") as well if want a bit more consistency

2 Likes
1 Like

Oh I’m sorry, I didn’t checked that

There are a couple of other posts, I do recommend searching up first before creating your topic :slightly_smiling_face:

1 Like

game.Workspace isnt risky to use in my opinion. i never had a case where workspace was slow to load. i have used game.Workspace for thousand of times and never had an single problem using it.

1 Like

It doesn’t ensure that you get the service you’re wanting, it’s only risky to use if you’re making a public resource that requires a service, in the event someone’s service is named differently, it will error, there may be other cases where it can fail, such as if a service ever changes name or if something else has the name of the service you’re wanting in the DataModel

Eitherways it’s always good practice to use the safest method possible, GetService as it uses a ClassName look up rather than indexing

As soon as I was about to make an edit correcting my mistake, others decided to correct it as well, I did not know Workspace was a property of the datamodel, thought it was another child like any other service, so they’re actually all the same

i dont see why anyone would name an datamodel or change the name of workspace. pretty stupid to do that. Yes i agree it is good practice to use GetService but i think its a waste of time to use it on workspace

1 Like

Workspace is actually a property of the DataModel. Properties have precedence over children when using dot syntax. In this case, game.Workspace is as safe as the rest to use.

2 Likes

i think the best way to get workspace is workspace

1 Like

For consistency purposes, you should use GetService for Workspace as well. It doesn’t look pretty to reference one service differently than others, using GetService is the standard and conventional way of getting services, and is good practice since not all services are created and GetService will create a service if not found.

1 Like