エンジンクラス
Player
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
プロパティ
方法
イベント
CharacterAdded(character: Model):RBXScriptSignal |
CharacterAppearanceLoaded(character: Model):RBXScriptSignal |
CharacterRemoving(character: Model):RBXScriptSignal |
Chatted(message: string,recipient: Player):RBXScriptSignal |
Idled(time: number):RBXScriptSignal |
OnTeleport(teleportState: Enum.TeleportState,placeId: number,spawnName: string):RBXScriptSignal |
APIリファレンス
プロパティ
AutoJumpEnabled
コードサンプル
オートジャンプ切り替え
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
local function update()
-- ボタンのテキストを更新
if player.AutoJumpEnabled then
button.Text = "オートジャンプはオンです"
else
button.Text = "オートジャンプはオフです"
end
-- プレイヤーのキャラクターにプロパティを反映
if player.Character then
local human = player.Character:FindFirstChild("Humanoid")
if human then
human.AutoJumpEnabled = player.AutoJumpEnabled
end
end
end
local function onActivated()
-- オートジャンプを切り替え
player.AutoJumpEnabled = not player.AutoJumpEnabled
-- その他を更新
update()
end
button.Activated:Connect(onActivated)
update()CameraMode
コードサンプル
一人称視点でプレイ
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMode = Enum.CameraMode.LockFirstPersonCharacterAppearance
DataComplexity
DataReady
FollowUserId
コードサンプル
フォロワーアラート
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 = "あなたは " .. newPlayer.Name .. " にフォローされてこのゲームに来ました!"
task.delay(3, function()
if textLabel then
textLabel:Destroy()
end
end)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)HasRobloxSubscription
コードサンプル
ロブロックスのサブスクリプションステータスを確認
local Players = game:GetService("Players")
local player = Players.LocalPlayer
if player.HasRobloxSubscription then
-- サブスクライバー専用のコンテンツまたは特典を付与
endMembershipType
PartyId
コードサンプル
プレイヤー.PartyId
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local partyId = player.PartyId
if partyId ~= "" then
print("プレイヤーはID: " .. partyId .. " のパーティに参加しています")
else
print("プレイヤーはパーティに参加していません")
end
player:GetPropertyChangedSignal("PartyId"):Connect(function()
if player.PartyId ~= "" then
print("プレイヤーはID: " .. player.PartyId .. " のパーティに参加しました")
else
print("プレイヤーはパーティを離れました")
end
end)
end)RespawnLocation
コードサンプル
タッチでスポーン変更
local Players = game:GetService("Players")
local function addSpawn(spawnLocation)
-- スポーンがタッチされたときにリッスンします
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")
-- キャラクターが死んでいないことを確認します
if humanoid and humanoid:GetState() ~= Enum.HumanoidStateType.Dead then
print("スポーンが設定されました")
player.RespawnLocation = spawnLocation
end
end
end
end)
end
local firstSpawn
-- ワークスペース内のスポーンを調べます
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
-- 新しいプレイヤーをリッスンします
Players.PlayerAdded:Connect(playerAdded)
-- 既存のプレイヤーを処理します
for _, player in pairs(Players:GetPlayers()) do
playerAdded(player)
endThirdPartyTextChatRestrictionStatus
UserId
コードサンプル
プレイヤー.UserId
local Players = game:GetService("Players")
local function onPlayerAdded(player)
print(player.UserId)
end
Players.PlayerAdded:Connect(onPlayerAdded)データストアからリーダーボードへ
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
-- データの取得に失敗しました
warn(result)
end
leaderstats.Parent = player
end
Players.PlayerAdded:Connect(onPlayerAdded)userId
方法
ClearCharacterAppearance
Player:ClearCharacterAppearance():()
戻り値
()
コードサンプル
キャラクターの外見をクリアする方法
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local function onChildRemoved(child)
print(child.ClassName, "がキャラクターから削除されました")
end
character.ChildRemoved:Connect(onChildRemoved)
player:ClearCharacterAppearance()
--> ボディカラーがキャラクターから削除されました
--> シャツグラフィックがキャラクターから削除されました
--> シャツがキャラクターから削除されました
--> パンツがキャラクターから削除されました
--> キャラクターメッシュがキャラクターから削除されました
--> 帽子がキャラクターから削除されました
--> シャツがキャラクターから削除されましたClearCachedAvatarAppearance
Player:ClearCachedAvatarAppearance():()
戻り値
()
DistanceFromCharacter
GetFriendsOnline
GetFriendsOnlineAsync
パラメータ
| 既定値: 200 |
戻り値
コードサンプル
オンライン接続のリストを取得
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local success, result = pcall(player.GetFriendsOnlineAsync, player, 10)
if success then
for _, friend in pairs(result) do
print(friend.UserName)
end
else
warn("オンラインプレイヤーの取得に失敗しました: " .. result)
endGetJoinData
戻り値
コードサンプル
トラフィックソースの追跡
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
-- 提供されたソースが有効かどうかを確認
if source and table.find(ALLOWED_SOURCES, source) then
-- ソースの人気を追跡するためにデータストアを更新
local success, result = pcall(analyticsStore.IncrementAsync, analyticsStore, source)
if success then
print(player.Name, "が", source, "から参加しました - 合計:", result)
else
warn("参加ソースの記録に失敗しました: " .. result)
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)リファラル URL ジェネレーター
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 -- 再帰的プロパティ更新を避ける
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)
-- テーブルを文字列に変換する
local jsonEncodedData = HttpService:JSONEncode(data)
if #jsonEncodedData <= DATA_CHARACTER_LIMIT then
-- スペースなどの無効な可能性のある文字をエスケープする
local urlEncodedData = HttpService:UrlEncode(jsonEncodedData)
return true, urlEncodedData
else
-- 文字制限エラーを報告する
return false, ("エンコードされたテーブルが %d 文字の制限を超えています"):format(DATA_CHARACTER_LIMIT)
end
end
local sampleData = {
joinMessage = "こんにちは!",
urlCreationDate = os.time(),
magicNumbers = {
534,
1337,
746733573,
},
}
local success, encodedData = encodeTableAsLaunchData(sampleData)
if success then
print(encodedData)
else
warn("起動データのエンコードに失敗しました: " .. encodedData)
endJSON起動データのデコード
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local launchData = player:GetJoinData().LaunchData
if launchData then
-- データをデコードしようとしています
local success, result = pcall(HttpService.JSONDecode, HttpService, launchData)
if success then
print(player.Name, "データを使用して参加しました:", result)
else
-- これはおそらくユーザーがURLをいじったためです
warn("起動データの解析に失敗しました:" .. result)
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)サーバーテレポートデータの例
local Players = game:GetService("Players")
local approvedPlaceIds = { 1 } -- 承認されたPlaceIdsをここに挿入
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()
-- このデータが承認された場所から送信されたことを確認
if isPlaceIdApproved(joinData.SourcePlaceId) then
local teleportData = joinData.TeleportData
if teleportData then
local currentLevel = teleportData.currentLevel
print(player.Name .. " はレベル " .. currentLevel .. " にいます")
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)GetRankInGroup
GetRankInGroupAsync
GetRoleInGroup
GetRoleInGroupAsync
HasAppearanceLoaded
戻り値
コードサンプル
プレイヤーの外見が読み込まれたか確認する
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)IsBestFriendsWith
IsFriendsWith
isFriendsWith
IsInGroup
IsVerified
LoadBoolean
loadBoolean
LoadCharacter
LoadCharacterAppearance
LoadCharacterAsync
Player:LoadCharacterAsync():()
戻り値
()
コードサンプル
自動読み込みをオフにしてキャラクターのリスポーンをシミュレート
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:LoadCharacterAsync()
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
player:LoadCharacterAsync()
end
Players.PlayerAdded:Connect(onPlayerAdded)LoadCharacterWithHumanoidDescription
LoadCharacterWithHumanoidDescriptionAsync
Player:LoadCharacterWithHumanoidDescriptionAsync(
):()
パラメータ
| 既定値: "Default" |
戻り値
()
コードサンプル
ヒューマノイド説明を用いてキャラクターを生成
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:LoadCharacterWithHumanoidDescriptionAsync(humanoidDescription)
end
Players.PlayerAdded:Connect(onPlayerAdded)LoadInstance
loadInstance
LoadNumber
loadNumber
LoadString
loadString
Move
戻り値
()
コードサンプル
カメラに対するプレイヤーの移動
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
-- プレイヤーのキャラクターとヒューマノイドを待機します。これは :Move() を呼び出す前に存在している必要があります。
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
character:WaitForChild("Humanoid")
-- プレイヤーは、実行時のカメラの位置から50スタッド離れるまで移動します。
localPlayer:Move(Vector3.new(0, 0, -50), true)RequestStreamAroundAsync
SaveBoolean
saveBoolean
SaveInstance
saveInstance
SaveNumber
saveNumber
SaveString
saveString
WaitForDataReady
waitForDataReady
イベント
CharacterAdded
パラメータ
コードサンプル
プレイヤーのスポーンとデスポーンの検出
local Players = game:GetService("Players")
local function onCharacterAdded(character)
print(character.Name .. " がスポーンしました")
end
local function onCharacterRemoving(character)
print(character.Name .. " がデスポーンしています")
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")
local function destroyAccessory(object)
if object:IsA("Hat") or object:IsA("Accessory") then
object:Destroy()
end
end
local function onCharacterAdded(character)
-- アクセサリを除去する前に短い間待機して、
-- "Something unexpectedly set ___ parent to NULL" の警告を避けます
RunService.Stepped:Wait()
-- プレイヤーのキャラクターに既存のアクセサリがあるかチェックします
for _, child in pairs(character:GetChildren()) do
destroyAccessory(child)
end
-- キャラクターに帽子が追加されるのは、
-- CharacterAdded が発火してから少し後かもしれないので、ChildAdded を使ってそれを監視します
character.ChildAdded:Connect(destroyAccessory)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)CharacterAppearanceLoaded
パラメータ
コードサンプル
ロード後にアクセサリーを削除
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- この時点ですべてのアクセサリーが読み込まれました
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("%d 個のアクセサリーを %s のために破壊します"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- プレイヤーが退出した後に接続を切断することを確認します
-- プレイヤーがガーベジコレクトされるのを許可するため
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)CharacterRemoving
パラメータ
コードサンプル
プレイヤーのスポーンとデスポーンの検出
local Players = game:GetService("Players")
local function onCharacterAdded(character)
print(character.Name .. " がスポーンしました")
end
local function onCharacterRemoving(character)
print(character.Name .. " がデスポーンしています")
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
player.CharacterRemoving:Connect(onCharacterRemoving)
end
Players.PlayerAdded:Connect(onPlayerAdded)Chatted
OnTeleport
Player.OnTeleport(
パラメータ
コードサンプル
プレイヤー.OnTeleport
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("テレポートが始まりました (" .. playerOnTeleport.Name .. ")")
elseif teleportState == Enum.TeleportState.WaitingForServer then
print("サーバーを待っています (" .. playerOnTeleport.Name .. ")")
elseif teleportState == Enum.TeleportState.InProgress then
print("テレポート進行中 (" .. playerOnTeleport.Name .. ")")
elseif teleportState == Enum.TeleportState.Failed then
print("テレポートに失敗しました! (" .. playerOnTeleport.Name .. ")")
end
end)
end)