Playersクラス
ひとことで言うと
ゲームに参加しているプレイヤーを管理するサービスです。プレイヤーが参加したとき・退出したときのイベントを使えます。
公式の説明(英語):A service that contains presently connected Player objects.
使用例
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)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)スクリプトは、Luauの型チェック(luau-lsp)で確認しています。
クラスの関係
プロパティ(9)
| 名前と書き方 | 説明 |
|---|---|
BanningEnabledPlayers.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. |
BubbleChatPlayers.BubbleChat: boolean | Indicates whether or not bubble chat is enabled. It is set with the Class.Players:SetChatStyle() method. |
CharacterAutoLoadsPlayers.CharacterAutoLoads: boolean | Indicates whether Class.Player.Character|characters will respawn automatically. |
ClassicChatPlayers.ClassicChat: boolean | Indicates whether or not classic chat is enabled; set by the Class.Players:SetChatStyle() method. |
LocalPlayerPlayers.LocalPlayer: Player | LocalScriptで、自分自身のプレイヤーを表します。サーバー側のScriptではnilです。The Player that the LocalScript is running for. |
MaxPlayersPlayers.MaxPlayers: int | 1つのサーバーに参加できる最大人数。The maximum number of players that can be in a server. |
PreferredPlayersPlayers.PreferredPlayers: int | The preferred number of players for a server. |
RespawnTimePlayers.RespawnTime: float | Controls the amount of time taken for a players character to respawn. |
UseStrafingAnimationsPlayers.UseStrafingAnimations: boolean | Determines whether R15 character models play directional strafing and backpedaling animations instead of always turning to face their direction of movement. |
メソッド(19)
| 名前と書き方 | 説明 |
|---|---|
BanAsyncPlayers: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. |
ChatPlayers:Chat(message: string): () | Makes the local player chat the given message. |
CreateHumanoidModelFromDescriptionAsyncPlayers: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. |
CreateHumanoidModelFromUserIdAsyncPlayers: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. |
GetBanHistoryAsyncPlayers: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. |
GetCharacterAppearanceInfoAsyncPlayers:GetCharacterAppearanceInfoAsync(userId: User): Dictionary | Returns information about the character appearance of a given user. |
GetFriendsAsyncPlayers:GetFriendsAsync(userId: User): FriendPages | Returns a FriendPages object which contains information for all of the given player's friends. |
GetHumanoidDescriptionFromOutfitIdAsyncPlayers:GetHumanoidDescriptionFromOutfitIdAsync(outfitId: int64): HumanoidDescription | Returns the HumanoidDescription for a specified outfit, which will be set with the parts/colors/Animations etc of the outfit. |
GetHumanoidDescriptionFromUserIdAsyncPlayers:GetHumanoidDescriptionFromUserIdAsync(userId: User): HumanoidDescription | Returns a HumanoidDescription which specifies everything equipped for the avatar of the user specified by the passed in userId. |
GetNameFromUserIdAsyncPlayers:GetNameFromUserIdAsync(userId: User): string | Sends a query to the Roblox website for the username of an account with a given Class.Player.UserId|UserId. |
GetPlayerByUserIdPlayers:GetPlayerByUserId(userId: User): Player | Returns the Player with the given Class.Player.UserId|UserId if they are in-experience. |
GetPlayerFromCharacterPlayers:GetPlayerFromCharacter(character: Model): Player | キャラクター(Model)から、そのプレイヤーを調べて返します。ふれたのがプレイヤーかを調べるときによく使います。Returns the Player whose Player.Character matches the given instance, or nil if one cannot be found. |
GetPlayersPlayers:GetPlayers(): List<Player> | 参加しているプレイヤーをすべて配列で返します。Returns a table of all presently connected Player objects. |
GetProfileConfigurationFromUserIdAsyncPlayers:GetProfileConfigurationFromUserIdAsync(userId: User): ProfileConfiguration | Returns the profile configuration of a user as a dictionary. |
GetUserIdFromNameAsyncPlayers:GetUserIdFromNameAsync(userName: string): int64 | Sends a query to the Roblox website for the Class.Player.UserId|userId of an account with a given username. |
GetUserThumbnailAsyncPlayers: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. |
SetChatStylePlayers:SetChatStyle(style: ChatStyle): () | Sets whether BubbleChat and ClassicChat are being used, and tells TeamChat and Chat what to do. |
TeamChatPlayers:TeamChat(message: string): () | Makes the local player chat the given message, which will only be viewable by users on the same team. |
UnbanAsyncPlayers: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. |
イベント(4)
| 名前と書き方 | 説明 |
|---|---|
PlayerAddedPlayers.PlayerAdded(player: Player) | プレイヤーがゲームに参加したときに発生するイベントです。リーダーボードの準備などに使います。Fires when a player enters the experience. |
PlayerMembershipChangedPlayers.PlayerMembershipChanged(player: Player) | Fires when the experience server recognizes that a player's membership has changed. |
PlayerRemovingPlayers.PlayerRemoving(player: Player, reason: PlayerExitReason) | プレイヤーがゲームから退出するときに発生するイベントです。データの保存などに使います。Fires when a player is about to leave the experience. |
UserSubscriptionStatusChangedPlayers.UserSubscriptionStatusChanged(user: Player, subscriptionId: string) | Fires when the experience server recognizes that the user's status for a certain subscription has changed. |
受け継いでいるメンバー
Instance から受け継いでいるもの(46)
Archivable・Capabilities・IsInSandbox・Name・Parent・PredictionMode・Sandboxed・AddTag・ClearAllChildren・Clone・Destroy・FindFirstAncestor・FindFirstAncestorOfClass・FindFirstAncestorWhichIsA・FindFirstChild・FindFirstChildOfClass・FindFirstChildWhichIsA・FindFirstDescendant・GetActor・GetAttribute・GetAttributeChangedSignal・GetAttributes・GetChildren・GetDebugId・GetDescendants・GetFullName・GetStyled・GetStyledPropertyChangedSignal・GetTags・HasTag・IsAncestorOf・IsDescendantOf・IsPropertyModified・QueryDescendants・RemoveTag・ResetPropertyToDefault・SetAttribute・WaitForChild・AncestryChanged・AttributeChanged・ChildAdded・ChildRemoved・DescendantAdded・DescendantRemoving・Destroying・StyledPropertiesChanged
Object から受け継いでいるもの(4)
Playersを使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(Players)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。