# Players（ロブロックス クラス）

> ゲームに参加しているプレイヤーを管理するサービスです。プレイヤーが参加したとき・退出したときのイベントを使えます。

- URL：https://roblox.minecraft-okinawa.com/reference/classes/Players/
- 公式：https://create.roblox.com/docs/reference/engine/classes/Players
- 受け継いでいるクラス：Instance

## 使用例：リーダーボード（leaderstats）を作る

（Script／置く場所：ServerScriptService）

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

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = 0
	coins.Parent = leaderstats
end)
```

## 使用例：参加したプレイヤーの歩く速さを変える

（Script／置く場所：ServerScriptService）

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

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid") :: Humanoid
		humanoid.WalkSpeed = 32
	end)
end)
```

## プロパティ

- `Players.BanningEnabled: boolean`：Enables or disables the three Players methods (Class.Players:BanAsync()|BanAsync(), Class.Players:UnbanAsync()|UnbanAsync(), and Class.Players:GetBanHistoryAsync()|GetBanHistoryAsync()) that constitute the ban API. This property cannot be set through developer-facing Luau and must be set in Studio through the Players properties window.
- `Players.BubbleChat: boolean`：Indicates whether or not bubble chat is enabled. It is set with the Class.Players:SetChatStyle() method.
- `Players.CharacterAutoLoads: boolean`：Indicates whether Class.Player.Character|characters will respawn automatically.
- `Players.ClassicChat: boolean`：Indicates whether or not classic chat is enabled; set by the Class.Players:SetChatStyle() method.
- `Players.LocalPlayer: Player`：LocalScriptで、自分自身のプレイヤーを表します。サーバー側のScriptではnilです。
- `Players.MaxPlayers: int`：1つのサーバーに参加できる最大人数。
- `Players.PreferredPlayers: int`：The preferred number of players for a server.
- `Players.RespawnTime: float`：Controls the amount of time taken for a players character to respawn.
- `Players.UseStrafingAnimations: boolean`：Determines whether R15 character models play directional strafing and backpedaling animations instead of always turning to face their direction of movement.

## メソッド

- `Players:BanAsync(config: Dictionary): ()`：Bans users from your experience, with options to specify duration, reason, whether the ban applies to the entire universe or just the current place, and more. This method is enabled and disabled by the Players.BanningEnabled property, which you can toggle in Studio.
- `Players:Chat(message: string): ()`：Makes the local player chat the given message.
- `Players:CreateHumanoidModelFromDescriptionAsync(description: HumanoidDescription, rigType: HumanoidRigType, assetTypeVerification: AssetTypeVerification): Model`：Returns a character Model equipped with everything specified in the passed in HumanoidDescription. If HumanoidDescription.UseAvatarSettings is set to true, Avatar Settings in the experience will be applied to the returned model.
- `Players:CreateHumanoidModelFromUserIdAsync(userId: User): Model`：Returns a character Model set-up with everything equipped to match the avatar of the user specified by the passed in userId.
- `Players:GetBanHistoryAsync(userId: User): BanHistoryPages`：Retrieves the ban and unban history of any user within the experience's universe. This method is enabled and disabled by the Players.BanningEnabled property, which you can toggle in Studio.
- `Players:GetCharacterAppearanceInfoAsync(userId: User): Dictionary`：Returns information about the character appearance of a given user.
- `Players:GetFriendsAsync(userId: User): FriendPages`：Returns a FriendPages object which contains information for all of the given player's friends.
- `Players:GetHumanoidDescriptionFromOutfitIdAsync(outfitId: int64): HumanoidDescription`：Returns the HumanoidDescription for a specified outfit, which will be set with the parts/colors/Animations etc of the outfit.
- `Players:GetHumanoidDescriptionFromUserIdAsync(userId: User): HumanoidDescription`：Returns a HumanoidDescription which specifies everything equipped for the avatar of the user specified by the passed in userId.
- `Players:GetNameFromUserIdAsync(userId: User): string`：Sends a query to the Roblox website for the username of an account with a given Class.Player.UserId|UserId.
- `Players:GetPlayerByUserId(userId: User): Player`：Returns the Player with the given Class.Player.UserId|UserId if they are in-experience.
- `Players:GetPlayerFromCharacter(character: Model): Player`：キャラクター（Model）から、そのプレイヤーを調べて返します。ふれたのがプレイヤーかを調べるときによく使います。
- `Players:GetPlayers(): List<Player>`：参加しているプレイヤーをすべて配列で返します。
- `Players:GetProfileConfigurationFromUserIdAsync(userId: User): ProfileConfiguration`：Returns the profile configuration of a user as a dictionary.
- `Players:GetUserIdFromNameAsync(userName: string): int64`：Sends a query to the Roblox website for the Class.Player.UserId|userId of an account with a given username.
- `Players:GetUserThumbnailAsync(userId: User, thumbnailType: ThumbnailType, thumbnailSize: ThumbnailSize): Tuple`：Returns the content URL of a player thumbnail given the size and type, as well as a boolean describing if the image is ready to use.
- `Players:SetChatStyle(style: ChatStyle): ()`：Sets whether BubbleChat and ClassicChat are being used, and tells TeamChat and Chat what to do.
- `Players:TeamChat(message: string): ()`：Makes the local player chat the given message, which will only be viewable by users on the same team.
- `Players:UnbanAsync(config: Dictionary): ()`：Unbans players banned from Class.Players:BanAsync() or the User Restrictions Open Cloud API. This method is enabled and disabled by the Players.BanningEnabled property, which you can toggle in Studio.

## イベント

- `Players.PlayerAdded(player: Player)`：プレイヤーがゲームに参加したときに発生するイベントです。リーダーボードの準備などに使います。
- `Players.PlayerMembershipChanged(player: Player)`：Fires when the experience server recognizes that a player's membership has changed.
- `Players.PlayerRemoving(player: Player, reason: PlayerExitReason)`：プレイヤーがゲームから退出するときに発生するイベントです。データの保存などに使います。
- `Players.UserSubscriptionStatusChanged(user: Player, subscriptionId: string)`：Fires when the experience server recognizes that the user's status for a certain subscription has changed.

英語の説明とメンバー一覧：Roblox Creator Documentation（CC BY 4.0）。日本語の解説はこのサイト独自のものです。

執筆：鈴木孝昌（現役プロジェクトマネージャー／プログラミング講師）／運営：沖縄マイクラ部 プログラミングスクール「クロスウェーブ」（https://minecraft-okinawa.com/）