Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ You can also combine functions inside a `Class.LocalScript|LocalScript`. For exa

```lua
local MarketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local button = script.Parent

-- Replace the placeholder ID with your developer product ID
Expand Down
6 changes: 4 additions & 2 deletions content/en-us/reference/engine/classes/Backpack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ description: |
The Backpack can be accessed from both the client and the server.
```lua
local Players = game:GetService("Players")
-- Accessing Backpack from a Server Script:
game.Players.PlayerName.Backpack
local backpack = Players.PlayerName.Backpack
-- Accessing Backpack from a LocalScript:
game.Players.LocalPlayer.Backpack
local backpack = Players.LocalPlayer.Backpack
```
code_samples:
- Backpack-Give-Tool
Expand Down
7 changes: 5 additions & 2 deletions content/en-us/reference/engine/classes/GuiObject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1417,11 +1417,14 @@ events:
of the user's mouse relative to a GUI element:

```lua
local Players = game:GetService("Players")

local CustomScrollingFrame = script.Parent
local SubFrame = CustomScrollingFrame:FindFirstChild("SubFrame")

local mouse = game.Players.LocalPlayer:GetMouse()
function getPosition(X, Y)
local mouse = Players.LocalPlayer:GetMouse()

local function getPosition(X, Y)
local gui_X = CustomScrollingFrame.AbsolutePosition.X
local gui_Y = CustomScrollingFrame.AbsolutePosition.Y

Expand Down
4 changes: 3 additions & 1 deletion content/en-us/reference/engine/classes/Object.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ methods:
`Datatype.BrickColor` property:
```lua
local Players = game:GetService("Players")
local function paintFigure(character, color)
-- Iterate over the child objects of the character
for _, child in character:GetChildren() do
Expand All @@ -165,7 +167,7 @@ methods:
end
end
end
paintFigure(game.Players.Player.Character, BrickColor.new("Bright blue"))
paintFigure(Players.Player.Character, BrickColor.new("Bright blue"))
```
Since all classes inherit from `Class.Object`, calling
Expand Down
8 changes: 6 additions & 2 deletions content/en-us/reference/engine/classes/Tool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,11 @@ events:
player clicks while the created tool is equipped.
```lua
local Players = game:GetService("Players")
local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.Parent = game.Players.LocalPlayer.Backpack
tool.Parent = Players.LocalPlayer.Backpack
function onActivation()
print("Tool activated")
Expand Down Expand Up @@ -423,9 +425,11 @@ events:
player releases their click while the tool is equipped and activated.
```lua
local Players = game:GetService("Players")
local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.Parent = game.Players.LocalPlayer.Backpack
tool.Parent = Players.LocalPlayer.Backpack
function toolDeactivated()
print("Tool deactivated")
Expand Down
3 changes: 2 additions & 1 deletion content/en-us/reference/engine/classes/Translator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ methods:
text as the second argument:
```lua
local Players = game:GetService("Players")
local LocalizationService = game:GetService("LocalizationService")
local success, translator = pcall(function()
return LocalizationService:GetTranslatorForPlayerAsync(game.Players.LocalPlayer)
return LocalizationService:GetTranslatorForPlayerAsync(Players.LocalPlayer)
end)
if success then
Expand Down
Loading