Player
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
A プレイヤー オブジェクトは、現在接続されているクライアントです。これらのオブジェクトは、新しいプレイヤーが接続すると Players サービスに追加され、最終的にサーバーから切断すると削除されます。
Instance.Name プロパティは、プレイヤーのユーザー名を反映します。プレイヤーに関する情報を保存するときは、プレイヤーがユーザー名を変更する可能性があるため、その Player.UserId を使用する必要があります。
プレイヤーオブジェクトを操作するための Players サービスには、複数の同様の方法があります。それらのそれぞれの Instance メソッドを使用してください:
- Players:GetPlayers() を使用して、現在のプレイヤーオブジェクトのテーブルを取得できます;再び、これを Instance:GetChildren() の代わりに使用します。
- プレイヤーオブジェクトの追加を検出するには、 イベントを使用することをお勧めします ( サービスではなく)。
- 同様に、Players.PlayerRemoving でプレイヤーオブジェクトの削除を検出できますが、プレイヤーが削除される前の **** で発動し、プレイヤーが削除された後の Instance.ChildRemoved では発動しません。削除または削除後に削除される可能性のあるプレイヤーに関する情報を保存している場合は、これが重要です。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player)
-- Create a container for leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
-- Create one leaderstat value
local vScore = Instance.new("IntValue")
vScore.Name = "Score"
vScore.Value = 0
vScore.Parent = leaderstats
-- Add to player (displaying it)
leaderstats.Parent = player
end
Players.PlayerAdded:Connect(onPlayerAdded)
概要
プロパティ
プレイヤーのアカウント年齢を日で説明します。
モバイルデバイスを使用しているプレイヤーのキャラクターが、障害物に当たると自動的にジャンプするかどうかを決定します。
プレイヤーのカメラがズームアウトできる最大距離。
プレイヤーのカメラがズームできる最小距離。
カメラのモードを第一人称か第三人称に変更します。
プレイヤーがスポーンすると、キャラクターの外観がロードされるかどうかを決定します。 false の場合、プレイヤーはデフォルトの外外見でスポーンします。
キャラクターの外観がプレイヤーの character に使用されるアカウントのユーザーIDを決定します。
カメラとプレイヤーの間のオブジェクトをデフォルトカメラが処理する方法を設定します。
Roblox のデスクトップバージョンを使用するとき、プレイヤーのカメラ移動モードを決定します。
Roblox のデスクトップバージョンを使用するとき、プレイヤーのキャラクター移動モードを決定します。
プレイヤーがマウスロックを切り替えられるかどうかを決定します。
タッチデバイスを使用すると、プレイヤーのカメラ移動モードを決定します。
タッチデバイスを使用すると、プレイヤーのキャラクター移動モードを決定します。
プレイヤーに関連するユーザーIDのディスプレイ名。
プレイヤーがゲームにフォローされたプレイヤーのユーザーIDを説明します。
プレイヤー側ゲームプレイが現在停止しているかどうか。
プレイヤーが認証済みのバッジを持っているかどうかを示します。
このプレイヤーが他のヒューマノイドのヘルスバーを見る距離を設定します。0に設定すると、ヘルスバーは表示されません。
このプロパティは、ローカルプレイヤーが Roblox アカウントに設定したローカルIDを表示します。
アカウントのメンバータイプを説明します。
このプレイヤーが他のヒューモイドの名前を見る距離を設定します。0に設定すると、名前は非表示になります。
プレイヤーが特定のチームにいるかどうかを決定します。
パーツを周囲の再複製に焦点を合わせます。
設設定するされた場合、プレイヤーは指定された SpawnLocation で再生します。
プレイヤーが関連するチームを決定します。
プレイヤーが関連するチームを決定します。
すべてのユーザーアカウントに割り当てられたユニークな識別整数。
方法
プレイヤーのキャラクターからすべてのアクセサリーや他のキャラクターの外観オブジェクトを削除します。
キャラクターの頭と指定された Vector3 ポイントの間の距離を返します。プレイヤーにキャラクターがない場合は、0を返します。
Player がエクスペリエンスに参加する方法を説明する情報を含む辞書を返します。
クライアントに使用されているマウスを返します。
孤立したネットワークの遅延を秒で返します。
プレイヤーのキャラクターの表示がロードされたかどうかを返します。
プレイヤーが具体的な、現実世界のシグナルで認証されているかどうかを返します。
強制的にプレイヤーをゲームから切断し、オプションでメッセージを提供します。
プレイヤーのキャラクターが指定された方向に歩き、停止またはプレイヤーによって中断されるまで歩行します(コントロールを使操作する)。
プレイヤーの AccountAge を設定します。
プレイヤーがフィルタリングされたチャットか、通常のチャットを見るかどうかを設定します。
オンラインの友達の辞書を返します。
グループ内でプレイヤーのランクを整数として返し、0はメンバーではなく、255はグループの所有者です。
グループ内でプレイヤーの役割を文字列または「ゲスト」として返します。プレイヤーがグループの一部でない場合は「ゲスト」です。
プレイヤーが指定された Player.UserId のユーザーの友達かどうかをチェックします。
プレイヤーが指定された ID のグループのメンバーかどうかをチェックします。
プレイヤーの新しいキャラクターを作成し、古いものを削除します。また、プレイヤーの Backpack と PlayerGui をクリアします。
スポーンして、パスされた HumanoidDescription に装備されているものすべてを備えます。
サーバーが指定された場所の周りのプレイヤーにストリームするリクエスト。
イベント
プレイヤーのキャラクターがスポーンまたはリスポーンすると、発射されます。
Player.Character の完全な外観が挿入されたときに発火します。
プレイヤーのキャラクターが削除される直前に発射されます。
Roblox が提供したチャットバーを使用してゲーム内でチャットするときに発火します。
このイベントは、ゲームエンジンが player を待機として分類した後、約 2分発動します。時間は、その時点から経過した秒数です。
プレイヤーの TeleportState が変更されたときに発射されます。
プロパティ
AccountAge
アカウント年齢は、プレイヤーのアカウントが何日前に登録されたかを記述する Player プロパティです。スクリプトでアクセスできない Player:SetAccountAge() 関数を使用して設定されています。
このプロパティは、条件付きで新しい Roblox プレイヤーのコンテンツ (チュートリアルなど) を表示するのに便利です。
コードサンプル
local Players = game:GetService("Players")
local MAX_AGE_NEW_PLAYER = 7 -- one week
local MIN_AGE_VETERAN = 365 -- one year
-- This function marks a part with text using a BillboardGui
local function mark(part, text)
local bbgui = Instance.new("BillboardGui")
bbgui.AlwaysOnTop = true
bbgui.StudsOffsetWorldSpace = Vector3.new(0, 2, 0)
bbgui.Size = UDim2.new(0, 200, 0, 50)
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0) -- Fill parent
textLabel.Text = text
textLabel.TextColor3 = Color3.new(1, 1, 1)
textLabel.TextStrokeTransparency = 0
textLabel.BackgroundTransparency = 1
textLabel.Parent = bbgui
-- Add to part
bbgui.Parent = part
bbgui.Adornee = part
end
local function onPlayerSpawned(player, character)
local head = character:WaitForChild("Head")
if player.AccountAge >= MIN_AGE_VETERAN then
mark(head, "Veteran Player")
elseif player.AccountAge <= MAX_AGE_NEW_PLAYER then
mark(head, "New Player")
else
mark(head, "Regular Player")
end
end
local function onPlayerAdded(player)
-- Listen for this player spawning
if player.Character then
onPlayerSpawned(player, player.Character)
end
player.CharacterAdded:Connect(function()
onPlayerSpawned(player, player.Character)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
AutoJumpEnabled
AutoJumpEnabled プロパティは、モバイルデバイスを使用して Player.Character の Player が障害物に衝突すると自動的にジャンプするかどうかを決定します。これにより、モバイルデバイス上でレベルをより適切にナビゲートできます。
プレイヤーがゲームに参加すると、StarterPlayer.AutoJumpEnabled 値がこのプロパティの初期状態を決定します。次に、このプロパティは、スポーン時の プロパティの値を決定します。言い換えれば、これらの 3 つのプロパティを使用して、文字ごと、プレイヤーごと、ゲームごとの自動ジャンプ動作を設定できます。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
local function update()
-- Update button text
if player.AutoJumpEnabled then
button.Text = "Auto-Jump is ON"
else
button.Text = "Auto-Jump is OFF"
end
-- Reflect the property in the player's character, if they have one
if player.Character then
local human = player.Character:FindFirstChild("Humanoid")
if human then
human.AutoJumpEnabled = player.AutoJumpEnabled
end
end
end
local function onActivated()
-- Toggle auto-jump
player.AutoJumpEnabled = not player.AutoJumpEnabled
-- Update everything else
update()
end
button.Activated:Connect(onActivated)
update()
CameraMaxZoomDistance
CameraMaxZoomDistance Player プロパティは、カメラがデフォルトのカメラからキャラクターまでの最大距離をスタッドで設定します。
言い換えれば、プレイヤーのカメラがズームアウトできる最大距離を制御します。
このプロパティのデフォルト値は、StarterPlayer.CameraMaxZoomDistance によって設定されます。この値が Player.CameraMinZoomDistance より低い値に設定されると、CameraMinZoomDistanceに増加します。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMaxZoomDistance = 50
player.CameraMinZoomDistance = 75
CameraMinZoomDistance
CameraMinZoonDistance Player プロパティは、カメラがデフォルトのカメラからキャラクターまでの最小距離をスタッドで設定します。
言い換えれば、プレイヤーのカメラがズームできる最小距離を制御します。
このプロパティのデフォルト値は、StarterPlayer.CameraMinZoomDistance によって設定されます。この値が Player.CameraMaxZoomDistance より高い値に設定されると、CameraMaxZoomDistanceに減少します。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMaxZoomDistance = 50
player.CameraMinZoomDistance = 75
CameraMode
カメラモード プロパティは、プレイヤーのカメラモードを設定し、デフォルトで第三者になります。
3人称
デフォルトの三人称モード ( Enum.CameraMode.Classic ) では、キャラクターはカメラに表示されます。このモードでは、デフォルトの動作は次のとおりです:
- プレイヤーは右クリックしてドラッグ (マウス)、タップしてドラッグ (モバイル)、セカンダリーサムスティック (ゲームパッド) を使用するか、左/右矢印 (キーボード) を押してカメラをキャラクターの周りに回転させます。
- プレイヤーがキャラクターを移動すると、対応する移動方向に面します。
- プレイヤーは自由にズームインやアウトを行うことができ、フルズーム中の最初の人にさえズームインすることができます。
最初の人
1人称モード ( Enum.CameraMode.LockFirstPerson ) では、プレイヤーのカメラが全体的にズームされます。 プロパティが に設定されていてビジブルな GUI が存在しない限り、マウスを移動したり、モバイルでタップドラッグしたり、ゲームパッドのセカンダリースティックを使用したりすると、カメラがキャラクターの周りに回転します。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMode = Enum.CameraMode.LockFirstPerson
CanLoadCharacterAppearance
CanLoadCharacterAppearance Player プロパティは、プレイヤーがスポーンするときにキャラクターの外観がロードされるかどうかを決定します。このプロパティのデフォルト値は、StarterPlayer.LoadPlayerAppearance によって設定されます。
if true であれば、キャラクタはプレイヤーの Player.CharacterAppearanceId に対応するプレイヤーの外観をロードします。
偽り である場合、プレイヤーはデフォルトの外観でスポーンします - 帽子、シャツ、パンツなどがないグレーのキャラクターモデル
キャラクターがスポーンした後にプロパティを設定しようとすると、キャラクターは変更されません。新しい外外見をロードするには、Player:LoadCharacter() を呼び出す必要があります。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CanLoadCharacterAppearance = false
Character
キャラクター プロパティには、Model に含まれる Humanoid 、ボディパーツ、スクリプト、その他のオブジェクトが含まれており、経験中にプレイヤーのアバターをシミュレートするために必要なものです。モデルは Workspace に親属していますが、移動することができます。Players.CharacterAutoLoads が true になると自動的にロードされ、そうでない場合は Player:LoadCharacter() を使用して手動でロードできます。
最初はこのプロパティは nil であり、プレイヤーのキャラクターが最初にスポーンすると設定されます。 イベントを使用して、プレイヤーのキャラクターが正しくロードされたときを検出し、 イベントを使用して、キャラクターがデスポーンする直前を検出します。このプロパティで Object:GetPropertyChangedSignal() を使用しないようにします。
注: が、 または からプレイヤーの または にクローンされ、古いキャラクターモデルが置換される前によく実行されるため、 は、古いモデルの プロパティが参照される可能性があります。そのため、LocalScript の下で、例えば、StarterGui または StarterPack で、 キャラクター の親が使用する前にnilでないことを確認することが望ましいです:
local Players = game:GetService("Players")local player = Players.LocalPlayerlocal character = player.Characterif not character or character.Parent == nil thencharacter = player.CharacterAdded:Wait()end
CharacterAppearanceId
このプロパティは、キャラクターの外観がプレイヤーの character に使用されるアカウントのユーザーIDを決定します。デフォルトでは、このプロパティは Player.UserId で、プレイヤーのアバターを Roblox ウェブサイトで作成したとおりに使用します。
このプロパティを別のアカウントのユーザー ID に変更すると、プレイヤーがそのアカウントの外見 (帽子、シャツ、パンツなど) で生成されます。
ゲームは、StarterPlayer.LoadCharacterAppearance プロパティを変更することで、プレイヤーのキャラクターの外観がゲームにロードされるかどうかを切り替えることもできます。
コードサンプル
local Players = game:GetService("Players")
local disguiseCommand = "/disguise "
local function onPlayerChatted(player, message)
if message:sub(1, disguiseCommand:len()):lower() == disguiseCommand:lower() then
local input = message:sub(disguiseCommand:len() + 1)
local id = tonumber(input)
if not id then -- Number failed to parse, maybe they typed a username instead
pcall(function() -- This call can fail sometimes!
id = Players:GetUserIdFromNameAsync(input) -- Fetch ID from name
end)
end
if id then
-- Set character appearance then respawn
player.CharacterAppearanceId = id
player:LoadCharacter()
else
-- We couldn't get an ID from their input
end
end
end
local function onPlayerAdded(player)
player.Chatted:Connect(function(...)
onPlayerChatted(player, ...)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
DevCameraOcclusionMode
カメラとカメラの主題の間のオブジェクトを処理するデフォルトカメラスクリプトの方法を定義します。StarterPlayer.DevCameraOcclusionMode によって設定され、個々のプレイヤーに変更できません。
デフォルト値は Zoom (0) です。利用可能なモードのリストについては、Enum.DevCameraOcclusionMode を参照してください。
DevComputerCameraMode
DevComputerCameraMode プロパティは、マウスとキーボードを使用した装置でプレイヤーがカメラを動かす方法を決定します。使用可能な各カメラコントロールモードの説明は、Enum.DevComputerCameraMovementMode を参照してください。このプロパティは LocalScript (サーバーで設定する必要があります) を使用して設定できません (サーバーで Script で設定する必要があります)。
このプロパティのデフォルト値は、StarterPlayer.DevComputerCameraMovementMode によって決まります。
このプロパティ名の「コンピュータ」という単語は、TouchEnabled 、GamepadEnabled デバイスではないものを指します。
ユーザー選択 に設定すると、プレイヤーは Roblox ゲーム設定の任意のコントロールモードを選択できます ( スクリプト可能 を除く)。一全般的に、プレイヤーがアクセシビリティを最大限に高めるためにコントロールモードを選択できるようにするのが良い考えです。
このプロパティを スクリプト可能 に設定して、カスタムコントロールスキームを作成できます。
このプロパティは、タッチ有効デバイスを使用しているプレイヤーには影響しません。代わりに Player.DevTouchCameraMode を参照してください。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Set the player's camera movement mode on computers to classic
player.DevComputerCameraMode = Enum.DevComputerCameraMovementMode.Classic
DevComputerMovementMode
DevComputerMovementMode プロパティは、マウスとキーボードを使用した装置でプレイヤーがキャラクターを移動する方法を決定します。利用可能な各移動コントロールモードの説明は、Enum.DevComputerMovementMode を参照してください。このプロパティは LocalScript (サーバーで設定する必要があります) を使用して設定できません (サーバーで Script で設定する必要があります)。
このプロパティのデフォルト値は、StarterPlayer.DevComputerMovementMode によって決まります。
このプロパティ名の「コンピュータ」という単語は、TouchEnabled デバイスではないものを指します。
ユーザー選択 に設定すると、プレイヤーは Roblox ゲーム設定の任意のコントロールモードを選択できます ( スクリプト可能 を除く)。一全般的に、プレイヤーがアクセシビリティを最大限に高めるためにコントロールモードを選択できるようにするのが良い考えです。
このプロパティを スクリプト可能 に設定して、カスタムコントロールスキームを作成できます。
このプロパティは、タッチ可能なデバイスを使用しているプレイヤーには影響しません。代わりに Player.DevTouchMovementMode を参照してください。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player: Player)
-- Set the player's movement mode on desktop devices to click-to-move
-- Once set, the player can right click in the game world and the character will move there.
player.DevComputerMovementMode = Enum.DevComputerMovementMode.ClickToMove
end
Players.PlayerAdded:Connect(onPlayerAdded)
DevEnableMouseLock
このプロパティは、プレイヤーが Shift を押して ロックを切り替えることができるかどうかを決定します。プレイヤーは、RoblRoblox(ロブロックス) のゲーム設定でマウスロックスイッチを無効にすることができます。デフォルトでは、このプロパティは StarterPlayer.EnableMouseLockOption の値に設定されます。これは、Script を使用して、実行時にサーバー側で設定できます。クライアント側で設定することはできません。
マウスロックが有効になっていると、プレイヤーのカーソルが画面の中央にロックされます。マウスを動かすと、カメラはプレイヤーの character の周りを軌道に乗り、キャラクターは camera と同じ方向を向きます。また、プレイヤーのキャラクターの右肩の上にカメラビューをオフセットします。
シフトロック関連の API が廃止プロセスにあるため、マウスをロックするために UserInputService.MouseBehavior を使用することをお勧めします。
コードサンプル
local Players = game:GetService("Players")
local function toggleMouseLock(player)
player.DevEnableMouseLock = not player.DevEnableMouseLock
if player.DevEnableMouseLock then
print("Mouse lock is available")
else
print("Mouse lock is not available")
end
end
local function onPlayerChatted(player, message, _recipient)
if message == "mouselock" then
toggleMouseLock(player)
end
end
local function onPlayerAdded(player)
player.Chatted:Connect(function(...)
onPlayerChatted(player, ...)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
DevTouchCameraMode
DevTouchCameraMode プロパティは、プレイヤーが TouchEnabled デバイス置を使用するときにカメラを移動する方法を決定します。使用可能な各カメラコントロールモードの説明は、Enum.DevTouchCameraMovementMode を参照してください。このプロパティは LocalScript (サーバーで Script を使用して設定する必要があります) を使用して設定できません。
このプロパティのデフォルト値は、StarterPlayer.DevTouchCameraMovementMode によって決まります。
ユーザー選択 に設定すると、プレイヤーは Roblox ゲーム設定の任意のコントロールモードを選択できます ( スクリプト可能 を除く)。一全般的に、プレイヤーがアクセシビリティを最大限に高めるためにコントロールモードを選択できるようにするのが良い考えです。
このプロパティを スクリプト可能 に設定して、カスタムコントロールスキームを作成できます。
このプロパティは、タッチ可能デバイスを使用していないプレイヤーには影響しません。代わりに Player.DevComputerCameraMovementMode を参照してください。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Set the player's camera movement mode on mobile devices to classic
player.DevTouchCameraMovementMode = Enum.DevTouchCameraMovementMode.Classic
DevTouchMovementMode
DevTouchMovementMode プロパティは、プレイヤーが TouchEnabled デバイス置を使用するときにキャラクターを移動する方法を決定します。利用可能な各移動コントロールモードの説明は、Enum.DevTouchMovementMode を参照してください。このプロパティは LocalScript (サーバーで Script を使用して設定する必要があります) を使用して設定できません。
このプロパティのデフォルト値は、StarterPlayer.DevTouchMovementMode によって決まります。
ユーザー選択 に設定すると、プレイヤーは Roblox ゲーム設定の任意のコントロールモードを選択できます ( スクリプト可能 を除く)。一全般的に、プレイヤーがアクセシビリティを最大限に高めるためにコントロールモードを選択できるようにするのが良い考えです。
このプロパティを スクリプト可能 に設定して、カスタムコントロールスキームを作成できます。
このプロパティは、タッチ可能デバイスを使用していないプレイヤーには影響しません。代わりに Player.DevComputerMovementMode を参照してください。
コードサンプル
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
-- Set the player's movement mode on mobile devices to a dynamic thumbstick
player.DevTouchMovementMode = Enum.DevTouchMovementMode.DynamicThumbstick
end)
DisplayName
The DisplayName は、Player オブジェクトに関連付けられた認証ユーザーの表示名を含む Player プロパティです。ユーザー名と異なり、ディスプレイ名はプレイヤーが他の人に表示する非唯一の名前です。Roblox ユーザーが選択していない場合、プロパティは Name プロパティと同じように読み取られます。
注意:
- 表示名は唯一ではないので、単一のインスタンスにいる 2 人のプレイヤーが同じ名前を持つ可能性があります。プレイヤーにグローバルにユニークな識別子が必要な場合は、Player.UserId (静的)またはPlayer.Name (現在のユーザー名)の代わりに使用してください。
- Player.LoadCharacter または Roblox エンジンで生成されたキャラクターは、Humanoid.DisplayName プロパティを Player.DisplayName プロパティに割り当てられます。
- 表示名には、Unicode 文字がストリン文字列に含まれる可能性があります。Unicode 文字を使用したストリングの作業方法については、UTF-8 を参照してください。
FollowUserId
フォローユーザーは、Player プレイヤーがゲームにフォローしたユーザーの Player.UserId を含むプロパティです。プレイヤーが誰かにゲームに従わなかった場合、このプロパティは 0 になります。このプロパティは、別のプレイヤーによってゲームにフォローされたプレイヤーを警告するのに便利です。
このユーザーIDと Players:GetNameFromUserIdAsync() 関数を使用して、プレイヤーの名前を追跡できます。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = player:WaitForChild("PlayerGui")
local function onPlayerAdded(newPlayer)
if newPlayer.FollowUserId == player.UserId then
local textLabel = Instance.new("TextLabel")
textLabel.Parent = screenGui
textLabel.Text = "You were followed to this game by " .. newPlayer.Name .. "!"
task.delay(3, function()
if textLabel then
textLabel:Destroy()
end
end)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
GameplayPaused
GameplayPaused プロパティは、プレイヤーが現在 有効になっている場所で一時停止状態にあるかどうかを示します。クライアントに設定されますが、サーバーにレプリケートされます。一時停止状況態を判断するには、このプロパティを使用できます。
参照してください:
- Workspace.StreamingEnabled コンテンツストリーミングが有効になっているかどうかを制御する
- Workspace.StreamingIntegrityMode と Enum.StreamingIntegrityMode で、ゲームプレイが一時停止したときの詳細情報。
HealthDisplayDistance
HealthDisplayDistance Player プロパティは、このプレイヤーが他の Humanoid 健康バーを見る距離をスタッドで設定します。0に設定すると、ヘルスバーは表示されません。このプロパティはデフォルトで StarterPlayer.HealthDisplayDistance に設定されます。
ヒューマノイドのヘルスバーが表示されている場合は、Humanoid.DisplayDistanceType を使用して表示タイプを設定できます。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.HealthDisplayDistance = 0
player.NameDisplayDistance = 0
LocaleId
ローカルID Player プロパティは、ローカルプレイヤーが Roblox アカウントに設定したローカルIDを表示します。ローカルに対して、2文字コード(例: "en-us")を含む文字列を保持します。
これは、ゲームのプレイヤーベースの地理的人口統計を決定するのに使用でき、また、経験中のコンテンツの自動翻訳のために使用されるローカルもあります(GuiBase2d.AutoLocalize)。このプロパティは、サーバーからプレイヤーのローカルにアクセスできるようにします。
参照してください LocalizationService.RobloxLocaleId , 内部コンテンツのローカライゼーションに使用されるローカルID。Roblox がまだローカルプレイヤーのセットローカルを内部でサポートしていないときの異なる値になります。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
print(player.LocaleId)
MembershipType
このプロパティは、メンバー資格を決定するためにのみ読み込まれることができ、他のメンバータイ入力に設定することはできません。アカウントのメンバータイプの枚入力 Enum.MembershipType を保持します。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
if player.MembershipType == Enum.MembershipType.Premium then
-- Take some action specifically for Premium members
end
NameDisplayDistance
NameDisplayDistance StarterPlayer プロパティは、このプレイヤーが他の Humanoid 名を見る距離をスタッドで設定します。プロパティが 0 に設定されている場合、名前は隠されます。このプロパティはデフォルトで StarterPlayer.NameDisplayDistance に設定されます。
ヒューマノイドのヘルスバーが表示されている場合は、Humanoid.DisplayDistanceType を使用して表示タイプを設定できます。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.HealthDisplayDistance = 0
player.NameDisplayDistance = 0
Neutral
中立プロパティは、プレイヤーが特定のチームにいるかどうかを決定します。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
if player.Neutral then
print("Player is neutral!")
else
print("Player is not neutral!")
end
PartyId
ReplicationFocus
レプリケーションフォーカス Player プロパティは、パーツをプレイヤーの周りにレプリケーションに焦点を合わせます。物理、ストリーミングなど、ネットワークを介して通信する異なる Roblox システムは、オブジェクトがレプリケーション焦点にどれほど近いかに応じて、異なる速度で複製されます。
このプロパティが nil になると、ローカルプレイヤーのキャラクターの PrimaryPart をレプリケーションの焦点として扱うデフォルト動作に戻ります。
このプロパティは、Script ではなく、LocalScript でのみサーバーに設定する必要があります。このプロパティは、パーツのネットワーク所有権を変更または更新しないことに注意してください。
コードサンプル
local Players = game:GetService("Players")
local PLAYER_NAME = "polarpanda16"
local player = Players:WaitForChild(PLAYER_NAME)
local part = Instance.new("Part")
part.Parent = workspace
part.Name = "ReplicationFocusPart"
part.Anchored = true
player.ReplicationFocus = part
RespawnLocation
設設定するされた場合、プレイヤーは指定された SpawnLocation で再生します。このプロパティは Luau を介してのみ設定でき、次の条件を満たす必要がある有効な SpawnLocation への参照を含む必要があります:
- 子孫の Workspace
RespawnLocation が有効な SpawnLocation に設定されていない場合、デフォルトのスポーンロジックが適用されます。この情報については、SpawnLocation ページを参照してください。
RespawnLocation の代替手段
- PVInstance:PivotTo() を使用して、独自のカスタムスポーンロジックを実装し、Player.Character を手動で移動します。
コードサンプル
local Players = game:GetService("Players")
local function addSpawn(spawnLocation)
-- listen for the spawn being touched
spawnLocation.Touched:Connect(function(hit)
local character = hit:FindFirstAncestorOfClass("Model")
if character then
local player = Players:GetPlayerFromCharacter(character)
if player and player.RespawnLocation ~= spawnLocation then
local humanoid = character:FindFirstChildOfClass("Humanoid")
-- make sure the character isn't dead
if humanoid and humanoid:GetState() ~= Enum.HumanoidStateType.Dead then
print("spawn set")
player.RespawnLocation = spawnLocation
end
end
end
end)
end
local firstSpawn
-- look through the workspace for spawns
for _, descendant in pairs(workspace:GetDescendants()) do
if descendant:IsA("SpawnLocation") then
if descendant.Name == "FirstSpawn" then
firstSpawn = descendant
end
addSpawn(descendant)
end
end
local function playerAdded(player)
player.RespawnLocation = firstSpawn
end
-- listen for new players
Players.PlayerAdded:Connect(playerAdded)
-- go through existing players
for _, player in pairs(Players:GetPlayers()) do
playerAdded(player)
end
StepIdOffset
Team
チームプロパティは、Team サービス内の Teams オブジェクトへの参照です。プレイヤーが属しているチームを決定します; Player がチームにないか、無効な Player.TeamColor を設定するっている場合、このプロパティは nil です。このプロパティが設定されると、プレイヤーは Team に参加し、関連するチームで Team.PlayerAdded イベントが発動します。同様に、Team.PlayerRemoved は、プロパティが特定の Team から削除されたときに発火します。
コードサンプル
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local teamPlaying = Teams.Playing
local teamSpectators = Teams.Spectating
local playCommand = "/play"
local function play(player)
player.Team = teamPlaying
player.TeamColor = teamPlaying.TeamColor
-- Respawn the player (moves them to spawn location)
player:LoadCharacter()
end
local function onPlayerDied(player, _character)
-- When someone dies, put them on the spectator team
player.Team = teamSpectators
end
local function onPlayerSpawned(player, character)
local human = character:WaitForChild("Humanoid")
human.Died:Connect(function()
onPlayerDied(player, character)
end)
end
local function onPlayerChatted(player, message)
if message:sub(1, playCommand:len()):lower() == playCommand then
play(player)
end
end
local function onPlayerAdded(player)
if player.Character then
onPlayerSpawned(player, player.Character)
end
player.CharacterAdded:Connect(function()
onPlayerSpawned(player, player.Character)
end)
player.Chatted:Connect(function(message, _recipient)
onPlayerChatted(player, message)
end)
end
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
-- Command to choose a team (note the trailing space)
local joinCommand = "/jointeam "
local function findTeamByName(name)
-- First, check for the exact name of a team
if Teams:FindFirstChild(name) then
return Teams[name]
end
-- Let's check for case-insensitive partial matches, like "red" for "Red Robins"
for _, team in pairs(Teams:GetChildren()) do
if team.Name:sub(1, name:len()):lower() == name:lower() then
return team
end
end
-- If we get to this point, no team matched the one we were looking for :(
end
local function onPlayerChatted(player, message, _recipient)
-- Note: string.sub(message, ...) is the same as message:sub(...)
if message:sub(1, joinCommand:len()):lower() == joinCommand:lower() then
-- Matched "/JOINTEAM xyz" to our join command prefix "/jointeam "
local teamName = message:sub(joinCommand:len() + 1) -- Cut out the "xyz" from "/jointeam xyz"
local team = findTeamByName(teamName)
if team then
-- Set the team!
player.Team = team
player.Neutral = false
else
-- Tell the player that team could not be found :(
player.Team = nil
player.Neutral = true
end
end
end
local function onPlayerAdded(player)
player.Chatted:Connect(function(...)
onPlayerChatted(player, ...)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
TeamColor
TeamColor プロパティは、チームの Team.TeamColor に基づいて、プレイヤーがどのチームと関連しているかを決定します。このプロパティを変更すると、どのチームも同じ を持っている場合によって、 が変更されます。チームオブジェクトに関連するチームカラーがない場合、プレイヤーはチームに関連付けられません。
このプロパティを使用するのではなく、それぞれの Team に Player.Team を設定するのがより良いアイデアです。このプロパティを設定すると、多くのスクリプトにわたって同じブリックカラー値が繰り返されることが多く、「自分を繰り返さない」(DRY)原則に従うときに避けたいものです。
コードサンプル
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local teamPlaying = Teams.Playing
local teamSpectators = Teams.Spectating
local playCommand = "/play"
local function play(player)
player.Team = teamPlaying
player.TeamColor = teamPlaying.TeamColor
-- Respawn the player (moves them to spawn location)
player:LoadCharacter()
end
local function onPlayerDied(player, _character)
-- When someone dies, put them on the spectator team
player.Team = teamSpectators
end
local function onPlayerSpawned(player, character)
local human = character:WaitForChild("Humanoid")
human.Died:Connect(function()
onPlayerDied(player, character)
end)
end
local function onPlayerChatted(player, message)
if message:sub(1, playCommand:len()):lower() == playCommand then
play(player)
end
end
local function onPlayerAdded(player)
if player.Character then
onPlayerSpawned(player, player.Character)
end
player.CharacterAdded:Connect(function()
onPlayerSpawned(player, player.Character)
end)
player.Chatted:Connect(function(message, _recipient)
onPlayerChatted(player, message)
end)
end
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
ThirdPartyTextChatRestrictionStatus
UserId
ユーザーID は、Roblox のすべてのユーザーアカウントを唯一かつ一貫して識別する読み込み専用の整数を含む プロパティです。プレイヤーの Instance.Name とは異なり、ユーザーの現在のユーザー名に応じて変更される可能性があるのとは異なり、この値は同じアカウントで決して変更されません。
このプロパティは、GlobalDataStores を使用してプレイヤーデータを保存/ロードするときに必須です。各プレイヤーがユニークなキーを持つように、プレイヤーのユーザーIDをデータストアのキーとして使用します。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player)
print(player.UserId)
end
Players.PlayerAdded:Connect(onPlayerAdded)
local Players = game:GetService("Players")
local player = Players:GetPlayerByUserId(1)
if player then
print("Player with userId 1 is in this server! Their name is: " .. player.Name)
else
print("Player with userId 1 is not in this server!")
end
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local OWNER_ID = 212423 -- can use game.CreatorId for published places
local BADGE_ID = 1
local ownerInGame = false
local function playerAdded(newPlayer)
if newPlayer.UserId == OWNER_ID then
-- if new player is the owner, set ownerInGame to true and give everyone the badge
ownerInGame = true
for _, player in pairs(Players:GetPlayers()) do
-- don't award the owner
if player ~= newPlayer then
BadgeService:AwardBadge(player.UserId, BADGE_ID)
end
end
elseif ownerInGame then
-- if the owner is in the game, award the badge
BadgeService:AwardBadge(newPlayer.UserId, BADGE_ID)
end
end
local function playerRemoving(oldPlayer)
if oldPlayer.UserId == OWNER_ID then
ownerInGame = false
end
end
Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(playerRemoving)
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local goldDataStore = DataStoreService:GetDataStore("Gold")
local STARTING_GOLD = 100
local function onPlayerAdded(player)
local playerKey = "Player_" .. player.UserId
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Parent = leaderstats
local success, result = pcall(function()
return goldDataStore:GetAsync(playerKey) or STARTING_GOLD
end)
if success then
gold.Value = result
else
-- Failed to retrieve data
warn(result)
end
leaderstats.Parent = player
end
Players.PlayerAdded:Connect(onPlayerAdded)
方法
ClearCharacterAppearance
クリアキャラクター表示機能は、すべての Accessory , Shirt , Pants , CharacterMesh , および BodyColors を指定されたプレイヤーの Player.Character から削除します。また、プレイヤーの胴体にある Tシャツ Decal も削除します。キャラクターのボディパーツの色と顔は変更されないままです。このメソッドは、プレイヤーがキャラクターを持っていない場合は何もしません。
t-shirts 、頭のメッシュ、または顔を削除しません。
戻り値
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local function onChildRemoved(child)
print(child.ClassName, "removed from character")
end
character.ChildRemoved:Connect(onChildRemoved)
player:ClearCharacterAppearance()
--> BodyColors removed from character
--> ShirtGraphic removed from character
--> Shirt removed from character
--> Pants removed from character
--> CharacterMesh removed from character
--> Hat removed from character
--> Shirt removed from character
DistanceFromCharacter
DistanceFromCharacter Player 関数は、キャラクターの頭と指定された Vector3 ポイントの間の距離を返します。プレイヤーに Player.Character がない場合は 0 を返します。
これは、ゲーム内のプレイヤーと他のオブジェクトや場所の距離を決定するときに便利です。
2つのプレイヤーのないインスタンスまたは位置の間の距離を決定したい場合は、フォロー中を使用できます:
local distance = (position1 - position2).Magnitude
パラメータ
プレイヤーの距離を測定する場所。
戻り値
プレイヤーと場所の間のスタッドの距離。
コードサンプル
local Players = game:GetService("Players")
for _, player in pairs(Players:GetPlayers()) do
print(player:DistanceFromCharacter(Vector3.new(0, 0, 0)))
end
GetJoinData
プレイヤーがエクスペリエンスに参加する方法を説明する情報を含む辞書を返します。辞書には次のフィールドのいずれかが含まれます:
<th>値タイプ</th><th>説明</th></tr></thead><tbody><tr><th>ソースゲームID</th><td>番号</td><td>経験の <code>Class.DataModel.GameId</code> からテレポートされた <code>プレイヤー</code> の。プレイヤーが現在のエクスペリエンスにテレポートし、サーバーがテレポート機能を呼び出している場合にのみ存在します。</td></tr><tr><th>ソースプレースID</th><td>番号</td><td>The <code>Class.DataModel.PlaceId</code> of the place the <code>プレイヤー</code> teleported from.プレイヤーが現在の場所にテレポートし、サーバーがテレポート機能を呼び出している場合にのみ存在します。</td></tr><tr><th>参照者プレイヤーID</th><td>番号</td><td>現在のプレイヤーをエクスペリエンスに招待したプレイヤーの <code>Class.Player.UserId</code>このデータを使用して、リファラーを識別し、報酬ロジックをトリガーします。</td></tr><tr><th>メンバー</th><td>配列</td><td>クラス.Player.UserId ユーザーが プレイヤー と一緒にテレポートした数を含む配列。プレイヤーがグループの一部としてテレポートした場合のみ表示されます。</td></tr><tr><th>Teleportデータ</th><td>変形</td><td>オリジナルのテレポートで指定された <code>teleportData</code> を反映します。プレイヤーがテレポートするサーバー間で情報を共有するのに便利。<code>teleportData</code> が指定され、サーバーがテレポート機能を呼び出している場合にのみ存在します。</td></tr><tr><th>ランチデータ</th><td>文字列</td><td><a href="/production/promotion/deeplinks">ディープリンク</a> URL または <code>Class.ExperienceInviteOptions.LaunchData</code> に指定された発進データを含むプレーンまたは JSON エンコードされた文字列。</td></tr><tr><th>ゲーム参加コンテキスト</th> <td>辞書</td><td>ゲーム参加のコンテキストに基づいて関連情報を含む辞書。次のキーが含まれています:<ul>JoinSource : Enum.JoinSource アイテムタイプ : オプション Enum.AvatarItemType アセットID : オプション string アウトフィットID : オプション string AssetType : オプション Enum.AssetType OutfitId : オプション string ></ul></td></tr></tbody>
キー |
---|
GetJoinData と TeleportData
サーバーがプレイヤーのテレポートを開始すると、このメソッドが返す辞書には、プレイヤーのテレポートデータが含まれます。Player:GetJoinData() メソッドは、サーバー上でテレポートデータを取得するためにのみ使用できます。クライアント上のデータを取得するには、TeleportService:GetLocalPlayerTeleportData() を使用します。
TeleportService:GetLocalPlayerTeleportData() とは異なり、Player:GetJoinData() は次のセキュリティ基準に合うテレポートデータのみを提供します:
- 過去 48 時間内に Roblox サーバーによって送信されたことが保証されています。
- この Player で送信されたことが保証されています。
- The SourcePlaceId と SourceGameId は、データが送信された場所と宇宙を保証するものです。これは、テレポートデータが承認された場プレースから来たことを確認できることを意味します。
このデータはクライアントによって送信されるため、悪用者によって悪用される可能性がまだあります。プレイヤーの通貨などの敏感なデータは、メモリストア のような安全なソリューションを介して送信する必要があります。
戻り値
PlaceId および UserId 値を含む辞書 (詳細の表を参照)。
コードサンプル
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local analyticsStore = DataStoreService:GetDataStore("Analytics")
local ALLOWED_SOURCES = {
"twitter",
"youtube",
"discord",
}
local function onPlayerAdded(player)
local source = player:GetJoinData().LaunchData
-- check if the provided source is valid
if source and table.find(ALLOWED_SOURCES, source) then
-- update the data store to track the source popularity
local success, result = pcall(analyticsStore.IncrementAsync, analyticsStore, source)
if success then
print(player.Name, "joined from", source, "- total:", result)
else
warn("Failed to record join source: " .. result)
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local DIRECT_JOIN_URL = "https://www.roblox.com/games/start?placeId=%d&launchData=%s"
local textBox = script.Parent
local function generateReferralURL(player)
return DIRECT_JOIN_URL:format(game.PlaceId, player.UserId)
end
local function highlightAll()
if -- avoid recursive property updates
textBox:IsFocused() and not (textBox.SelectionStart == 1 and textBox.CursorPosition == #textBox.Text + 1)
then
textBox.SelectionStart = 1
textBox.CursorPosition = #textBox.Text + 1
end
end
textBox.Focused:Connect(highlightAll)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(highlightAll)
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(highlightAll)
textBox.TextEditable = false
textBox.ClearTextOnFocus = false
textBox.Text = generateReferralURL(player)
local HttpService = game:GetService("HttpService")
local DATA_CHARACTER_LIMIT = 200
local function encodeTableAsLaunchData(data)
-- convert the table to a string
local jsonEncodedData = HttpService:JSONEncode(data)
if #jsonEncodedData <= DATA_CHARACTER_LIMIT then
-- escape potentially invalid characters, such as spaces
local urlEncodedData = HttpService:UrlEncode(jsonEncodedData)
return true, urlEncodedData
else
-- report character limit error
return false, ("Encoded table exceeds %d character limit"):format(DATA_CHARACTER_LIMIT)
end
end
local sampleData = {
joinMessage = "Hello!",
urlCreationDate = os.time(),
magicNumbers = {
534,
1337,
746733573,
},
}
local success, encodedData = encodeTableAsLaunchData(sampleData)
if success then
print(encodedData)
else
warn("failed to encode launch data: " .. encodedData)
end
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local launchData = player:GetJoinData().LaunchData
if launchData then
-- attempt to decode the data
local success, result = pcall(HttpService.JSONDecode, HttpService, launchData)
if success then
print(player.Name, "joined with data:", result)
else
-- this is probably due to the user messing with the URL
warn("Failed to parse launch data:" .. result)
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
local Players = game:GetService("Players")
local approvedPlaceIds = { 1 } -- insert approved PlaceIds here
local function isPlaceIdApproved(placeId)
for _, id in pairs(approvedPlaceIds) do
if id == placeId then
return true
end
end
return false
end
local function onPlayerAdded(player)
local joinData = player:GetJoinData()
-- verify this data was sent by an approved place
if isPlaceIdApproved(joinData.SourcePlaceId) then
local teleportData = joinData.TeleportData
if teleportData then
local currentLevel = teleportData.currentLevel
print(player.Name .. " is on level " .. currentLevel)
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
GetMouse
GetMouse Player 関数は、クライアントに使用されている Mouse を返します。プレイヤーのマウスインスタンスを使用して、左右のマウスボタンクリックと移動、場所を含むユーザーのマウス入力を追跡できます。
サービスは、ユーザーの入力を追跡するための追加の機能とイベントを提供します - 特にマウスを使用しないデバイスの場合。
注意:
- このアイテム は オンラインで期待通りに機能するために、LocalScript で使用する必要があります。
- 2014年7月の更新の後、マウスのアイコンはこの方法で設定できるようになりました。
戻り値
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onButton1Down()
print("Button 1 is down")
end
mouse.Button1Down:Connect(onButton1Down)
GetNetworkPing
GetNetworkPing は、秒ごとに Player の孤立したネットワーク遅延を返します。「Ping」は、クライアントからサーバーへのデータ送信時間、そして再び戻る時間の測定です。データのデシリアライズや処理は関与しません。
クライアント側の LocalScripts については、この関数は Players.LocalPlayer でのみ呼び出すことができます。この機能は、高いネットワーク遅延シナリオで発生する問題を識別してデバッグするのに便利です。また、遅延をマスキングするのにも便利で、プロジェクティルの投射アニメーションの速度を調整するなどです。
戻り値
HasAppearanceLoaded
HasAppearanceLoaded Player 関数は、プレイヤーの Player.Character の外観がロードされたかどうかを返します。
プレイヤーの外観には、プレイヤーの Shirt 、Pants 、および Accessories などのアイテムが含まれます。
これは、Players.PlayerAdded イベントを使用して追跡できるように、プレイヤーの外観が最初にゲームに参加した後にロードされたかどうかを判断するときに便利です。
戻り値
プレイヤーのキャラクターの表示がロードされたかどうかを示すブールン値。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local loaded = player:HasAppearanceLoaded()
print(loaded)
while not loaded do
loaded = player:HasAppearanceLoaded()
print(loaded)
task.wait()
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
IsVerified
プレイヤーの認証ステータスを示すボールーン値を返します。真になると、プレイヤーが認証されます。認証には、VOIP 電話番号または政府の身分証明書以外の確認が含まれますが、限定されていません。
IsVerified を実装するときは、実装が意図しないすべての未認証ユーザーをブロックしないように注意してください。
メソッドはバックエンドサーバーでのみ呼び出すことができます。クライアント側で呼び出すとエラーが発生します。さらに、このメソッドは常に Studio で false を返します。
戻り値
プレイヤーが認証されているかどうかを示すブール。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player)
print(player:IsVerified())
end
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Kick
Kick() メソッドでは、エクスペリエンスがクライアントを上手く切断し、オプションで接続が切断されたユーザーにメッセージを提供できます。これは悪用者をモデレートするのに便利です。信頼できる特定のユーザーにのみ、他のユーザーにこのメソッドをトリガーするように許可する必要があります。
このメソッドを引数なしで Player に呼び出すと、ユーザーがサーバーから切断され、デフォルトの通知メッセージが提供されます。このメソッドを、Player と一緒に、ストリングを第 1 引数として呼び出すと、デフォルトのメッセージを提供されたストリン文字列に置き換えます。
このメソッドを LocalScript から使用すると、ローカルユーザーのクライアントだけが追放されます。
パラメータ
ユーザーを追放するときに表示するメッセージ。
戻り値
Move
移動 Player 機能は、プレイヤーのキャラクターが指定された方向に歩き、停止するか、プレイヤーによって中断されるまで歩き続けます (コントロールを使操作して)。
これは、マップ上を移動する NPC Humanoids をスクリプトするときに便利ですが、実際のプレイヤーの入力によって制御されていません。
機能の 2番目の引数は、提供された Vector3 が世界の座標に対して移動するか(false)、プレイヤーの Camera (true)かを示します。
パラメータ
プレイヤーが移動するべき Vector3 方向。
プレイヤーがプレイヤーのカメラに対して移動すべきかどうかを示すブール。
戻り値
コードサンプル
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
-- Wait for the player's character and humanoid, which must exist before calling :Move()
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
character:WaitForChild("Humanoid")
-- The player will move until they are 50 studs away from the camera's position at the time of running
localPlayer:Move(Vector3.new(0, 0, -50), true)
SetAccountAge
SetAccountAge 機能は、プレイヤーの Player.AccountAge を日に設定します。
プレイヤーのアカウントが何日前に登録されたかを説明する Player プロパティを設定するために使用されます。
これはアカウント上のプレイヤーの年齢を設定しませんが、最初に作成された時点に比べてアカウント自体の年齢を設定します。
パラメータ
アカウントの日数の年齢。
戻り値
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player:SetAccountAge(100)
local Players = game:GetService("Players")
local MAX_AGE_NEW_PLAYER = 7 -- one week
local MIN_AGE_VETERAN = 365 -- one year
-- This function marks a part with text using a BillboardGui
local function mark(part, text)
local bbgui = Instance.new("BillboardGui")
bbgui.AlwaysOnTop = true
bbgui.StudsOffsetWorldSpace = Vector3.new(0, 2, 0)
bbgui.Size = UDim2.new(0, 200, 0, 50)
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0) -- Fill parent
textLabel.Text = text
textLabel.TextColor3 = Color3.new(1, 1, 1)
textLabel.TextStrokeTransparency = 0
textLabel.BackgroundTransparency = 1
textLabel.Parent = bbgui
-- Add to part
bbgui.Parent = part
bbgui.Adornee = part
end
local function onPlayerSpawned(player, character)
local head = character:WaitForChild("Head")
if player.AccountAge >= MIN_AGE_VETERAN then
mark(head, "Veteran Player")
elseif player.AccountAge <= MAX_AGE_NEW_PLAYER then
mark(head, "New Player")
else
mark(head, "Regular Player")
end
end
local function onPlayerAdded(player)
-- Listen for this player spawning
if player.Character then
onPlayerSpawned(player, player.Character)
end
player.CharacterAdded:Connect(function()
onPlayerSpawned(player, player.Character)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
SetSuperSafeChat
このメソッドは、プレイヤーが普通のチャットではなく TextService:FilterStringAsync() にフィルターされたチャットを見るかどうかを設定します。
local Players = game:GetService("Players")local player = Players.LocalPlayerplayer:SetSuperSafeChat(true)
プレイヤーがチャットをフィルタリング有効にしているかどうかにかかわらず、すべてのチャットは、他のプレイヤーに配信するか、プレイヤー自身の画面に配信するときに TextService でフィルタリングされる必要があります。TextService:FilterStringAsync() は、メッセージの意図した使用に応じて異なる方法でフィルタリングできる TextFilterResult オブジェクトを返します。
パラメータ
プレイヤーがフィルタリングされたチャットを見るかどうかを示すブール。
戻り値
GetFriendsOnline
この機能は、maxFriends 値によって制限されたオンラインの友達の辞書アレイを返します。機能は 30 秒のキャッシュを使用します。
返された配列では、いくつかのフィールドは特定の場所タイプのみに存在します。たとえば、 場所ID は、 場所タイプ が 0 (モバイルウェブサイト) のときに存在しません。
<th>種類</th><th>説明</th></tr></thead><tbody><tr><td><b>訪問者ID</b></td><td>番号</td><td>友達の <code>Class.Player.UserId</code> 。</td></tr><tr><td><b>ユーザー名</b></td><td>文字列</td><td>友達のユーザー名。</td></tr><tr><td><b>表示名称</b></td><td>文字列</td><td>友達人の <code>Class.Player.DisplayName</code> 。</td></tr><tr><td><b>最後のオンライン</b></td><td>文字列</td><td>友達が最後にオンラインだったとき。</td></tr><tr><td><b>オンライン IsOnline</b></td><td>ブールン値</td><td>友達が現在オンラインである場合。</td></tr><tr><td><b>最後の場所</b></td><td>文字列</td><td>友友達の現在の場所の名前。</td></tr><tr><td><b>プレースID</b></td><td>番号</td><td>友友達の最後の場所のプレースID。</td></tr><tr><td><b>ゲームID</b></td><td>文字列</td><td>友人の最後の場所の <code>データモデル/ジョブID</code>。</td></tr><tr><td><b>場所タイプ</b></td> <td>番号</td><td>フレンドの最後の場所のロケーションタイプ: 0 モバイルウェブサイト モバイルゲームのスタジオ 2 3 モバイルウェブサイトのチーム作成 モバイルゲームのスタジオのスタイプ モバイルウェブサイトのチーム作成 モバイルウェブサイトのアプリロケーションのアプリケーションのサイトのアプリロケーションのアプログのアプログのアプリアプリのアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリアプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリプリ</td></tr></tbody>
名前 |
---|
パラメータ
戻すオンラインの友達の最大数。
戻り値
オンラインの友達の辞書 (上の表を参照)。
コードサンプル
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local success, result = pcall(player.GetFriendsOnline, player, 10)
if success then
for _, friend in pairs(result) do
print(friend.UserName)
end
else
warn("Failed to get online players: " .. result)
end
GetRankInGroup
GetRankInGroup Player 関数は、プレイヤーのグループ内のランクを整数として返し、0はメンバーではなく、255はグループの所有者です。
これを Script で使用すると、LocalScript では最新情報を得られません。プレイヤーがゲーム中にグループを離れると、GetRankInGroup は退出するまで、そのグループにいると考え続けます。しかし、ローカルスクリプトで使用すると、このようなことは起こりません。
これは、メソッドが結果をキャッシュするためで、同じグループIDで同じプレイヤーに複数回 GetRankInGroup を呼び出すと、メソッドが最初に指定されたグループIDで呼び出されたときと同じ結果が得られます。キャッシュ行動はペア単位です:サーバーはクライアントと同じキャッシュを共有しません。
パラメータ
指定されたグループの groupId 。
戻り値
グループ内のプレイヤーのランク。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player)
if player:GetRankInGroup(2) == 255 then
print("Player is the owner of the group, 'LOL'!")
else
print("Player is NOT the owner of the group, 'LOL'!")
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
GetRoleInGroup
GetRoleInGroup Player 関数は、プレイヤーのグループ内の役割を文字列として返し、または ゲスト プレイヤーがグループの一部でない場合。
これを Script で使用すると、LocalScript では最新情報を得られません。プレイヤーがゲーム中にグループを離れると、GetRoleInGroup は退出するまで、そのグループにいると考え続けます。しかし、ローカルスクリプトで使用すると、このようなことは起こりません。
これは、メソッドが結果をキャッシュするためで、同じグループIDで同じプレイヤーに複数回 GetRoleInGroup を呼び出すと、メソッドが最初に指定されたグループIDで呼び出されたときと同じ結果が得られます。キャッシュ行動はペア単位です:サーバーはクライアントと同じキャッシュを共有しません。
パラメータ
指定されたグループの groupId。
戻り値
指定されたグループでのプレイヤーの役割、または ゲスト プレイヤーがメンバーでない場合。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player)
print("Player is ranked as '", player:GetRoleInGroup(2), "' in group, 'LOL'!")
end
Players.PlayerAdded:Connect(onPlayerAdded)
IsFriendsWith
この機能は、Roblox ウェブサイトにプレイヤーが他のユーザーの友人かどうかを尋ねるリクエストを送信し、そのユーザーの Player.UserId に基づいて。この機能は結果をキャッシュして、同じプレイヤーで同じ Player.UserId の複数の機能呼び出しが最新の結果を生成しない可能性があります。これは LocalScript で使用したときには発生しません。
パラメータ
指定されたプレイヤーの Player.UserId 。
戻り値
プレイヤーが指定されたユーザーの友人かどうかを示すブール。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player)
if player:IsFriendsWith(146569) then
print(player.Name .. " is friends with gordonrox24!")
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
IsInGroup
IsInGroup Player 関数は、Roblox ウェブサイトにプレイヤーがグループのメンバーかどうかを尋ねるリクエストを送信し、そのグループのIDを指定します。
これを Script で使用すると、LocalScript では最新情報を得られません。プレイヤーがゲーム中にグループを離れると、IsInGroup は退出するまで、そのグループにいると考え続けます。しかし、ローカルスクリプトで使用すると、このようなことは起こりません。
これは、メソッドが結果をキャッシュするためで、同じグループIDを持つ同じプレイヤーで複数の IsInGroup 呼び出しが行われると、メソッドが最初に指定されたグループIDで呼び出されたときと同じ結果が得られます。キャッシュ行動はペア単位です:サーバーはクライアントと同じキャッシュを共有しません。
パラメータ
指定されたグループの groupId。
戻り値
プレイヤーが指定されたグループに属しているかどうかを示すブール。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player)
if player:IsInGroup(7) then
print("Player is in the Roblox Fan club!")
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
LoadCharacter
LoadCharacter Player 関数は、プレイヤーのために新しいキャラクターを作成し、古いものを削除します。また、プレイヤーの Backpack と PlayerGui をクリアします。
これは、プレイヤーを殺さずにキャラクターを再読み込みたい場合、例えば、プレイヤーの Player.CharacterAppearance を変更後に新しいキャラクターの外観をロードしたい場合など、有用です。
注: 機能は Player:LoadCharacterBlocking() に似ていますが、リクエストは同期ではなく非同期で処理されます。これは、キャラクターのロード中に他のタスクが続行でき、ゲームのレンダリングやその他のタスクを含むことを意味します。また、この機能はスクリプトで使用できますが、LoadCharacterBlocking はできません。
個々のプレイヤーに LoadCharacter を呼んだ後、同じプレイヤーの Player.CharacterAppearanceLoaded イベントが発火した後に再度呼ぶことはお勧めしません。
キャラクターロードイベントの順序
R15 アバターで Player:LoadCharacter() を呼び出すと、次の順序でイベントが発生します (注: R6 順序は異なります):
- Player.Character セット
- Player.CharacterAdded が発火する
- Player.Changed は「キャラクター」の値で発火します
- キャラクターの外観初期化
- Player.CharacterAppearanceLoaded が発火する
- Character.Parent は DataModel に設定されます
- キャラクターリグが構築され、キャラクタースケールが拡大する
- キャラクターがスポーン地点に移動する
- LoadCharacter の返却
戻り値
コードサンプル
local Players = game:GetService("Players")
local RESPAWN_DELAY = 5
Players.CharacterAutoLoads = false
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local function onDied()
task.wait(RESPAWN_DELAY)
player:LoadCharacter()
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
player:LoadCharacter()
end
Players.PlayerAdded:Connect(onPlayerAdded)
LoadCharacterWithHumanoidDescription
この機能はアバターをスポーンし、パスされた HumanoidDescription に装備されているものすべてを備えます。
個々のプレイヤーに対して LoadCharacterWithHumanoidDescription を呼んだ後、同じプレイヤーの Player.CharacterAppearanceLoaded イベントが発動した後に、同じプレイヤーに対して再度機能を呼び出すことは推奨されません。
参照してください:
- ヒューマノイド説明システム、ヒューマノイド説明システムをより詳細に説明し、複数のスクリプト例を提供する記事
パラメータ
体部/色、ボディスケーリング、アクセサリ、衣衣装、アニメーションなど、ロードされたキャラクターに装備される特徴を含む AHumanoidDescription
戻り値
コードサンプル
local Players = game:GetService("Players")
Players.CharacterAutoLoads = false
local function onPlayerAdded(player)
local humanoidDescription = Instance.new("HumanoidDescription")
humanoidDescription.HatAccessory = "2551510151,2535600138"
humanoidDescription.BodyTypeScale = 0.1
humanoidDescription.ClimbAnimation = 619521311
humanoidDescription.Face = 86487700
humanoidDescription.GraphicTShirt = 1711661
humanoidDescription.HeadColor = Color3.new(0, 1, 0)
player:LoadCharacterWithHumanoidDescription(humanoidDescription)
end
Players.PlayerAdded:Connect(onPlayerAdded)
RequestStreamAroundAsync
インスタンス ストリーミング が有効になっているエクスペリエンスでは、3Dワールドの指定された X 、 Y 、 Z 場所のプレイヤー領域 (パーツと地形) にサーバーがストリームするリクエストが有効です。エクスペリエンスが、プレイヤーの CFrame が近い将来に指定された場所に設定されることを知っていると、有用です。この呼び出しで場所を提供しないと、プレイヤーは目的地のコンテンツをストリーミングしない可能性があり、ストリーミング停止または他の不適切な動作が発生する可能性があります。
この呼び出しの効果は一時的であり、指定された場所の周りでストリーミングされる内容に関する保証はありません。クライアントメモリの制限とネットワーク条件が、クライアント上で利用できるものに影響を与える可能性があります。
使用上の注意
エリアの周りでストリーミングをリクエストすることは、ストリーミングがクライアントのネットワークバンド幅、メモリ制限、その他の要因に影響を受けるため、リクエストが完了したときにコンテンツが存在する保証ではありません です 。
パラメータ
ストリーミングがリクエストされた世界の場所。
リクエストのオプションの期限切れ、エンジンがリクエストを放棄する前に position パラメータの周りの領域をストリーミングしようとする最大期間。値を指定しない場合、タイムアウトは効果的に無限です。しかし、クライアントがメモリが少ない場合、エンジンは期限切れ期間内のすべてのストリーミングリクエストを放棄します。
戻り値
イベント
CharacterAdded
キャラクター追加 イベントは、プレイヤーのキャラクターがスポーン(またはリスポーン)するときに発動します。このイベントは、Player.Character を非-nil 値に設定したり、Player:LoadCharacter() を呼んだりするとすぐに発動します。キャラクターがWorkspaceに親属する前に呼ばれます。
これは、プレイヤーのキャラクターが削除される直前に発動する Player.CharacterRemoving イベントと一緒に使用でき、通常は死後。このように、これらのイベントの両方は、プレイヤーが死んでから場プレースにリスポーンすると、複数回発射する可能性があります。プレイヤーがゲームに参加または退出するときを検出したい場合は、代わりに Players.PlayerAdded および Players.PlayerRemoving イベントを使用してください。
このイベントが発動すると、Humanoid とそのデフォルトの身体部位 (頭、胴体、手足) が存在しますが、Hats 、Shirts 、Pants のような衣類アイテムは、キャラクターに追加されるまで数秒かかる可能性があります。追加されたキャラクターに Instance.ChildAdded を接続して、これを検出するか、Player.CharacterAppearanceLoaded イベントがキャラクターにすべて装備されていることを確認するまで待ちます。
パラメータ
生成/再生したキャラクタのインスタンス。
コードサンプル
local Players = game:GetService("Players")
local function onCharacterAdded(character)
print(character.Name .. " has spawned")
end
local function onCharacterRemoving(character)
print(character.Name .. " is despawning")
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
player.CharacterRemoving:Connect(onCharacterRemoving)
end
Players.PlayerAdded:Connect(onPlayerAdded)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- This table maps "Player" objects to Vector3
local respawnLocations = {}
local function onCharacterAdded(character)
local player = Players:GetPlayerFromCharacter(character)
-- Check if we saved a respawn location for this player
if respawnLocations[player] then
-- Teleport the player there when their HumanoidRootPart is available
local hrp = character:WaitForChild("HumanoidRootPart")
-- Wait a brief moment before teleporting, as Roblox will teleport the
-- player to their designated SpawnLocation (which we will override)
RunService.Stepped:wait()
hrp.CFrame = CFrame.new(respawnLocations[player] + Vector3.new(0, 3.5, 0))
end
end
local function onCharacterRemoving(character)
-- Get the player and their HumanoidRootPart and save their death location
local player = Players:GetPlayerFromCharacter(character)
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp then
respawnLocations[player] = hrp.Position
end
end
local function onPlayerAdded(player)
-- Listen for spawns/despawns
player.CharacterAdded:Connect(onCharacterAdded)
player.CharacterRemoving:Connect(onCharacterRemoving)
end
local function onPlayerRemoved(player)
-- Forget the respawn location of any player who is leaving; this prevents
-- a memory leak if potentially many players visit
respawnLocations[player] = nil
end
-- Note that we're NOT using PlayerRemoving here, since CharacterRemoving fires
-- AFTER PlayerRemoving, we don't want to forget the respawn location then instantly
-- save another right after
Players.PlayerAdded:Connect(onPlayerAdded)
Players.ChildRemoved:Connect(onPlayerRemoved)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local function destroyAccessory(object)
if object:IsA("Hat") or object:IsA("Accessory") then
object:Destroy()
end
end
local function onCharacterAdded(character)
-- Wait a brief moment before removing accessories to avoid the
-- "Something unexpectedly set ___ parent to NULL" warning
RunService.Stepped:Wait()
-- Check for any existing accessories in the player's character
for _, child in pairs(character:GetChildren()) do
destroyAccessory(child)
end
-- Hats may be added to the character a moment after
-- CharacterAdded fires, so we listen for those using ChildAdded
character.ChildAdded:Connect(destroyAccessory)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
CharacterAppearanceLoaded
このイベントは、Player.Character の完全な外観が挿入されたときに発動します。
A Player.Character は一般的に、Accoutrements、Shirts、Pants、およびCharacterMeshesを含む外外見を変更するオブジェクトの範囲があります。このイベントは、すべてのこのオブジェクトが Player.Character に挿入されたときに発動します。
このイベントはサーバー上でのみ発動します。
このイベントの 1つの使用は、破棄する前にすべてのアクセサリがロードされていることを確認することです。以下の例を参照してください。
パラメータ
The Player.Character Model 。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- All accessories have loaded at this point
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("Destroying %d accessories for %s"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- Make sure we disconnect our connection to the player after they leave
-- to allow the player to get garbage collected
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)
CharacterRemoving
キャラクター削除イベントは、プレイヤーのキャラクターが削除される直前、例えばプレイヤーがリスポーンするときに発動します。
このイベントは、プレイヤーのキャラクターがスポーンまたはリスポーンするときに発動する Player.CharacterAdded イベントと並べて使用できます。たとえば、プレイヤーがスポーンして死ぬたびにメッセージを印刷したい場インスタンス:
local Players = game:GetService("Players")
local function onCharacterSpawned(player)
print(player.Name .. " is spawning")
end
local function onCharacterDespawned(player)
print(player.Name .. " is despawning")
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(function()
onCharacterSpawned(player)
end)
player.CharacterRemoving:Connect(function()
onCharacterDespawned(player)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
このイベントは、Character の Player のみに関連しています。代わりに、プレイヤーがゲームに参加/退出するタイミングを追跡する必要がある場合は、イベント Players.PlayerAdded と Players.PlayerRemoving を使用します。
パラメータ
削除されているキャラクタのインスタンス。
コードサンプル
game.Players.PlayerAdded:Connect(function(player)
player.CharacterRemoving:Connect(function(character)
print(character.Name .. " has died.")
end)
end)
Chatted
チャットイベントは、Player がメッセージを入力し、Roblox の提供されたチャットバーで Enter を押すと発動します。これはデフォルトのチャットスクリプトによるいくつかの Luau バインディングを使用して行われます。StarterGui:SetCoreGuiEnabled() を使用してチャットを防ぎ、チャットを無効にして Enum.CoreGuiType を無効にすることができます。
チャットコマンド
このイベントと、string.sub() や string.lower() などのストリング操作関数を使用すると、プレイヤー名のような引数でもチャットコマンドを作成できます。通常、コマンドは heal PlayerName のようなプレフィックスで始まります。文字列でプレフィックスをチェックするには、メッセージに string.sub() を使用してメッセージのサブストリングをチェックします:string.sub(message, 1, 6) == "/heal " (スペースの含有を注意してください)。次に、string.sub() でコマンドの残りを抽出します:string.sub(message, 7) はプレイヤー名と同じになります。そのプレイヤーが存在するかどうかをチェックし、存在する場合は、コマンドのアクションを実行します (この例では、回復する)。チャットコマンドの例のコードサンプルをチェックします。
フィルター
このイベントで発射されたメッセージテキストは フィルターなし です。チャットなどのプレイヤーの入力を他のプレイヤーにどの形式でも表示している場合、Chat:FilterStringAsync() を使用してフィルタリングする必要があります。自分のチャットシステムを作成するときは、これを意識してください; あなたのゲームがチャットを適切にフィルタリングしない場合、それに対してモデレーション行動が取られる可能性があります。
パラメータ
プレイヤーがチャットで入力したメッセージの内容。
廃止。 スピーチメッセージの場合、これはチャットメッセージの意図したターゲットであるプレイヤーでした。
コードサンプル
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onChatted(message)
-- do stuff with message and player
print(message)
end
player.Chatted:Connect(onChatted)
end
Players.PlayerAdded:Connect(onPlayerAdded)
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local teamPlaying = Teams.Playing
local teamSpectators = Teams.Spectating
local playCommand = "/play"
local function play(player)
player.Team = teamPlaying
player.TeamColor = teamPlaying.TeamColor
-- Respawn the player (moves them to spawn location)
player:LoadCharacter()
end
local function onPlayerDied(player, _character)
-- When someone dies, put them on the spectator team
player.Team = teamSpectators
end
local function onPlayerSpawned(player, character)
local human = character:WaitForChild("Humanoid")
human.Died:Connect(function()
onPlayerDied(player, character)
end)
end
local function onPlayerChatted(player, message)
if message:sub(1, playCommand:len()):lower() == playCommand then
play(player)
end
end
local function onPlayerAdded(player)
if player.Character then
onPlayerSpawned(player, player.Character)
end
player.CharacterAdded:Connect(function()
onPlayerSpawned(player, player.Character)
end)
player.Chatted:Connect(function(message, _recipient)
onPlayerChatted(player, message)
end)
end
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
-- Command to choose a team (note the trailing space)
local joinCommand = "/jointeam "
local function findTeamByName(name)
-- First, check for the exact name of a team
if Teams:FindFirstChild(name) then
return Teams[name]
end
-- Let's check for case-insensitive partial matches, like "red" for "Red Robins"
for _, team in pairs(Teams:GetChildren()) do
if team.Name:sub(1, name:len()):lower() == name:lower() then
return team
end
end
-- If we get to this point, no team matched the one we were looking for :(
end
local function onPlayerChatted(player, message, _recipient)
-- Note: string.sub(message, ...) is the same as message:sub(...)
if message:sub(1, joinCommand:len()):lower() == joinCommand:lower() then
-- Matched "/JOINTEAM xyz" to our join command prefix "/jointeam "
local teamName = message:sub(joinCommand:len() + 1) -- Cut out the "xyz" from "/jointeam xyz"
local team = findTeamByName(teamName)
if team then
-- Set the team!
player.Team = team
player.Neutral = false
else
-- Tell the player that team could not be found :(
player.Team = nil
player.Neutral = true
end
end
end
local function onPlayerAdded(player)
player.Chatted:Connect(function(...)
onPlayerChatted(player, ...)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Idled
このイベントは、ゲームエンジンが player を待機として分類した後、約 2分発動します。時間は、その時点から経過した秒数です。プレイヤーが待機状態のままである限り、イベントは 30 秒ごとに継続して発射します。
このイベントは、サーバースクリプトではなく、クライアントスクリプトでのみ発動します; RemoteEvent を使用して、サーバーの空きプレイヤーを通知します。
Roblox は、少なくとも 20 分間不活発なプレイヤーを自動的に切断するので、このイベントはプレイヤーに近い将来切断される可能性があることを警告するのに役立ち、20分前にプレイヤーを切断したり、他のキーボードから離れた(AFK)機能を使用したりします。
自動切断がどの頻度で発生するかを追跡するには、このイベントを Players.PlayerRemoving の発生と関連付けて試してください。
パラメータ
プレイヤーが待機していた時間(秒)。
コードサンプル
local Players = game:GetService("Players")
local function onIdled(idleTime)
print(`Player has been idle for {idleTime} seconds`)
if idleTime > 900 then
-- warn player that they've been idle for 15 minutes
-- and will be disconnected in another 5
end
end
Players.LocalPlayer.Idled:Connect(onIdled)
OnTeleport
プレイヤーの TeleportState が変更されたときに発射されます。このイベントは、テレポートが成功したかどうかを検出するのに便利です。
TeleportState とは何ですか?
テレポートリクエストが TeleportService を使用して作成されたとき、Player がテレポートされる前に、複数のステージがあります。現在のステージは、OnTeleport によって提供される Enum.TeleportState 値で表現されます。以下でこの実用的な例を見てください。
パラメータ
新しい Enum.TeleportState の Player 。
TeleportService:TeleportToSpawnByName() が使用された場合、テレポートするスポーンの名前。
コードサンプル
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local playerOnTeleport = player
player.OnTeleport:Connect(function(teleportState, _placeId, _spawnName)
if teleportState == Enum.TeleportState.Started then
print("Teleport started (" .. playerOnTeleport.Name .. ")")
elseif teleportState == Enum.TeleportState.WaitingForServer then
print("Teleport waiting for server (" .. playerOnTeleport.Name .. ")")
elseif teleportState == Enum.TeleportState.InProgress then
print("Teleport in progress (" .. playerOnTeleport.Name .. ")")
elseif teleportState == Enum.TeleportState.Failed then
print("Teleport failed! (" .. playerOnTeleport.Name .. ")")
end
end)
end)