Skip to content

Commit e13b4c3

Browse files
Simplify to workspace reference
1 parent cb04623 commit e13b4c3

File tree

11 files changed

+29
-62
lines changed

11 files changed

+29
-62
lines changed

content/en-us/production/monetization/immersive-ads.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,10 @@ For example, the following code sample uses `Class.PolicyService:GetPolicyInfoFo
334334
```lua
335335
local Players = game:GetService("Players")
336336
local PolicyService = game:GetService("PolicyService")
337-
local Workspace = game:GetService("Workspace")
338337

339338
local player = Players.LocalPlayer
340-
-- Sample assumes a "Main Portal Template" model exists under Workspace
341-
local mainPortal = Workspace:WaitForChild("Main Portal Template")
339+
-- Sample assumes a "Main Portal Template" model exists under workspace
340+
local mainPortal = workspace:WaitForChild("Main Portal Template")
342341

343342
-- Get the policy info for the user
344343
local success, result = pcall(PolicyService.GetPolicyInfoForPlayerAsync, PolicyService, player)

content/en-us/production/promotion/complying-with-advertising-standards.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ If you believe all the content in your experience collectively constitutes an ad
9292
```lua
9393
local Players = game:GetService("Players")
9494
local PolicyService = game:GetService("PolicyService")
95-
local Workspace = game:GetService("Workspace")
9695

9796
local player = Players.LocalPlayer
9897

content/en-us/reference/engine/classes/Camera.yaml

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@ properties:
6969
`Datatype.Vector3.new(10, 0, 0)`.
7070
7171
```lua
72-
local Workspace = game:GetService("Workspace")
73-
74-
local camera = Workspace.CurrentCamera
72+
local camera = workspace.CurrentCamera
7573
camera.CameraType = Enum.CameraType.Scriptable
7674
7775
local pos = Vector3.new(0, 10, 0)
7876
local lookAtPos = Vector3.new(10, 0, 0)
7977
80-
Workspace.CurrentCamera.CFrame = CFrame.lookAt(pos, lookAtPos)
78+
workspace.CurrentCamera.CFrame = CFrame.lookAt(pos, lookAtPos)
8179
```
8280
8381
Although the camera can be placed in the manner demonstrated above, you
@@ -93,9 +91,8 @@ properties:
9391
```lua
9492
local Players = game:GetService("Players")
9593
local TweenService = game:GetService("TweenService")
96-
local Workspace = game:GetService("Workspace")
9794
98-
local camera = Workspace.CurrentCamera
95+
local camera = workspace.CurrentCamera
9996
camera.CameraType = Enum.CameraType.Scriptable
10097
10198
local player = Players.LocalPlayer
@@ -149,10 +146,9 @@ properties:
149146
150147
```lua
151148
local Players = game:GetService("Players")
152-
local Workspace = game:GetService("Workspace")
153149
154150
local localPlayer = Players.LocalPlayer
155-
local camera = Workspace.CurrentCamera
151+
local camera = workspace.CurrentCamera
156152
157153
local function resetCameraSubject()
158154
if camera and localPlayer.Character then
@@ -378,9 +374,8 @@ properties:
378374
379375
```lua
380376
local UserInputService = game:GetService("UserInputService")
381-
local Workspace = game:GetService("Workspace")
382377
383-
local camera = Workspace.CurrentCamera
378+
local camera = workspace.CurrentCamera
384379
385380
local headCFrame = UserInputService:GetUserCFrame(Enum.UserCFrame.Head)
386381
headCFrame = headCFrame.Rotation + headCFrame.Position * camera.HeadScale
@@ -710,9 +705,7 @@ methods:
710705
should opt for the `Class.WorldRoot:Raycast()` method.
711706
712707
```lua
713-
local Workspace = game:GetService("Workspace")
714-
715-
local camera = Workspace.CurrentCamera
708+
local camera = workspace.CurrentCamera
716709
717710
local castPoints = {
718711
Vector3.new(0, 10, 0),
@@ -767,9 +760,8 @@ methods:
767760
768761
```lua
769762
local UserInputService = game:GetService("UserInputService")
770-
local Workspace = game:GetService("Workspace")
771763
772-
local camera = Workspace.CurrentCamera
764+
local camera = workspace.CurrentCamera
773765
774766
local headCFrame = UserInputService:GetUserCFrame(Enum.UserCFrame.Head)
775767
headCFrame = headCFrame.Rotation + headCFrame.Position * camera.HeadScale
@@ -1007,9 +999,7 @@ methods:
1007999
create a longer ray, you can do the following:
10081000
10091001
```lua
1010-
local Workspace = game:GetService("Workspace")
1011-
1012-
local camera = Workspace.CurrentCamera
1002+
local camera = workspace.CurrentCamera
10131003
local length = 500
10141004
local unitRay = camera:ScreenPointToRay(100, 100)
10151005
local extendedRay = Ray.new(unitRay.Origin, unitRay.Direction * length)
@@ -1216,9 +1206,7 @@ methods:
12161206
centre of the screen, for example:
12171207
12181208
```lua
1219-
local Workspace = game:GetService("Workspace")
1220-
1221-
local camera = Workspace.CurrentCamera
1209+
local camera = workspace.CurrentCamera
12221210
12231211
local viewportPoint = camera.ViewportSize / 2
12241212
local unitRay = camera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y, 0)
@@ -1228,9 +1216,7 @@ methods:
12281216
create a longer ray, you can do the following:
12291217
12301218
```lua
1231-
local Workspace = game:GetService("Workspace")
1232-
1233-
local camera = Workspace.CurrentCamera
1219+
local camera = workspace.CurrentCamera
12341220
12351221
local length = 500
12361222
local unitRay = camera:ScreenPointToRay(100, 100)
@@ -1287,9 +1273,7 @@ methods:
12871273
`Class.Camera:WorldToViewportPoint()|WorldToViewportPoint()`.
12881274
12891275
```lua
1290-
local Workspace = game:GetService("Workspace")
1291-
1292-
local camera = Workspace.CurrentCamera
1276+
local camera = workspace.CurrentCamera
12931277
12941278
local worldPoint = Vector3.new(0, 10, 0)
12951279
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)
@@ -1346,9 +1330,7 @@ methods:
13461330
`Class.Camera:WorldToScreenPoint()|WorldToScreenPoint()`.
13471331
13481332
```lua
1349-
local Workspace = game:GetService("Workspace")
1350-
1351-
local camera = Workspace.CurrentCamera
1333+
local camera = workspace.CurrentCamera
13521334
13531335
local worldPoint = Vector3.new(0, 10, 0)
13541336
local vector, onScreen = camera:WorldToViewportPoint(worldPoint)

content/en-us/reference/engine/classes/MeshPart.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ properties:
235235
applied to the mesh.
236236
237237
```
238-
local Workspace = game:GetService("Workspace")
239-
240-
local meshPart = Workspace.MeshPart
238+
local meshPart = workspace.MeshPart
241239
meshPart.TextureContent = Content.none -- No texture
242240
```
243241
@@ -263,9 +261,8 @@ properties:
263261
264262
```
265263
local AssetService = game:GetService("AssetService")
266-
local Workspace = game:GetService("Workspace")
267264
268-
local meshPart = Workspace.MeshPart
265+
local meshPart = workspace.MeshPart
269266
270267
local editableImage = AssetService:CreateEditableImageAsync(meshPart.TextureContent)
271268
meshPart.TextureContent = Content.fromObject(editableImage) -- Live updates
@@ -309,9 +306,7 @@ properties:
309306
to the mesh.
310307
311308
```
312-
local Workspace = game:GetService("Workspace")
313-
314-
local meshPart = Workspace.MeshPart
309+
local meshPart = workspace.MeshPart
315310
meshPart.TextureID = "" -- No texture
316311
```
317312

content/en-us/studio/microprofiler/using-microprofiler.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Now that the MicroProfiler has provided a starting point, you can troubleshoot t
6161
local endPosition = getRandomPosition()
6262
local direction = endPosition - startPosition
6363

64-
Workspace:Raycast(
64+
workspace:Raycast(
6565
startPosition,
6666
endPosition
6767
)
@@ -86,7 +86,7 @@ Now that the MicroProfiler has provided a starting point, you can troubleshoot t
8686
local endPosition = getRandomPosition()
8787
local direction = endPosition - startPosition
8888

89-
Workspace:Raycast(
89+
workspace:Raycast(
9090
startPosition,
9191
endPosition
9292
)

content/en-us/tutorials/curriculums/core/scripting/create-player-hazards.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ To create the basic water hazard:
5252

5353
```lua
5454
local Players = game:GetService("Players")
55-
local Workspace = game:GetService("Workspace")
5655

57-
local hazardsFolder = Workspace.World.Hazards
56+
local hazardsFolder = workspace.World.Hazards
5857
local hazards = hazardsFolder:GetChildren()
5958

6059
local function onHazardTouched(otherPart)

content/en-us/tutorials/curriculums/core/scripting/record-and-display-player-data.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,14 @@ data. To update **CoinService**:
295295

296296
```lua
297297
-- Initializing services and variables
298-
local Workspace = game:GetService("Workspace")
299298
local Players = game:GetService("Players")
300299
local ServerStorage = game:GetService("ServerStorage")
301300

302301
-- Modules
303302
local Leaderboard = require(ServerStorage.Leaderboard)
304303
local PlayerData = require(ServerStorage.PlayerData)
305304

306-
local coinsFolder = Workspace.World.Coins
305+
local coinsFolder = workspace.World.Coins
307306
local coins = coinsFolder:GetChildren()
308307

309308
local COIN_KEY_NAME = PlayerData.COIN_KEY_NAME

content/en-us/tutorials/curriculums/core/scripting/script-game-behavior.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ which tells the engine to run the script on the server, and prevents clients fro
6868

6969
```lua
7070
-- Initializing services and variables
71-
local Workspace = game:GetService("Workspace")
7271
local Players = game:GetService("Players")
7372

74-
local coinsFolder = Workspace.World.Coins
73+
local coinsFolder = workspace.World.Coins
7574
local coins = coinsFolder:GetChildren()
7675

7776
local COOLDOWN = 10
@@ -129,16 +128,15 @@ which tells the engine to run the script on the server, and prevents clients fro
129128
workspace for all references to coin objects with the
130129
`Class.Instance:GetChildren()|GetChildren()` method. This method returns an
131130
array containing everything parented to the object it's associated with,
132-
which in this case is the `Workspace.World.Coins` folder you created
131+
which in this case is the `workspace.World.Coins` folder you created
133132
previously.
134133
- **Defines a global variable** - The `COOLDOWN` variable is used later to
135134
define how long to disable a coin after it's collected.
136135

137136
```lua title="Initializing Services and Variables"
138-
local Workspace = game:GetService("Workspace")
139137
local Players = game:GetService("Players")
140138

141-
local coinsFolder = Workspace.World.Coins
139+
local coinsFolder = workspace.World.Coins
142140
local coins = coinsFolder:GetChildren()
143141

144142
local COOLDOWN = 10

content/en-us/tutorials/curriculums/user-interface-design/implement-designs-in-studio.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,6 @@ The following `ReplicatedStorage.FirstPersonBlasterVisuals` client script handle
19201920
``` lua
19211921
local Players = game:GetService("Players")
19221922
local ReplicatedStorage = game:GetService("ReplicatedStorage")
1923-
local Workspace = game:GetService("Workspace")
19241923
local RunService = game:GetService("RunService")
19251924

19261925
local BlastData = require(ReplicatedStorage.Blaster.BlastData)
@@ -1938,7 +1937,7 @@ local laserBlastedBindableEvent = ReplicatedStorage.Instances.LaserBlastedBindab
19381937
local RIG_OFFSET_FROM_CAMERA = CFrame.new(2, -2, -3) * CFrame.Angles(math.rad(0.25), math.rad(95.25), 0)
19391938

19401939
local localPlayer = Players.LocalPlayer
1941-
local currentCamera = Workspace.CurrentCamera
1940+
local currentCamera = workspace.CurrentCamera
19421941

19431942
local rigModel = nil
19441943
local cooldownBar = nil
@@ -1949,7 +1948,7 @@ local function addFirstPersonVisuals()
19491948

19501949
-- Add the first person rig
19511950
rigModel = blasterConfig.RigModel:Clone()
1952-
rigModel.Parent = Workspace
1951+
rigModel.Parent = workspace
19531952

19541953
-- Add the cooldownBar
19551954
cooldownBar = addCooldownBar(rigModel.PrimaryPart.CooldownBarAttachment)

content/en-us/tutorials/use-case-tutorials/animation/playing-character-animations.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,11 @@ To create a local script that will detect when the local player's character touc
216216
1. In the new script, paste the following code:
217217

218218
```lua
219-
local Workspace = game:GetService("Workspace")
220-
221219
local animation = script:WaitForChild("Animation")
222220
local humanoid = script.Parent:WaitForChild("Humanoid")
223221
local animator = humanoid:WaitForChild("Animator")
224222
local animationTrack = animator:LoadAnimation(animation)
225-
local animationDetector = Workspace:WaitForChild("AnimationDetector")
223+
local animationDetector = workspace:WaitForChild("AnimationDetector")
226224

227225
local debounce = false
228226

@@ -249,7 +247,7 @@ To create a local script that will detect when the local player's character touc
249247
</AccordionSummary>
250248
<AccordionDetails>
251249

252-
The `TriggerAnimation` script starts by getting the `Class.Workspace` service, which contains all objects that exist in the 3D world. This is important because the script needs to reference the `Class.Part` object acting as your volume.
250+
The `TriggerAnimation` script starts by setting variables for the Humanoid and necessary animation references. This is important because the script needs to reference these later.
253251

254252
For each player character that loads or respawns back into the experience, the script waits for:
255253

0 commit comments

Comments
 (0)