A 플레이어 개체는 현재 연결된 클라이언트입니다.이 개체는 새 플레이어가 연결되면 Players 서비스에 추가되고, 결국 서버에서 연결이 끊어지면 제거됩니다.
Instance.Name 속성은 플레이어의 사용자 이름을 반영합니다.플레이어에 대한 정보를 저장할 때 플레이어가 자신의 사용자 이름을 변경할 수 있기 때문에 그들의 Player.UserId를 사용해야 합니다.
플레이어 개체와 작업하기 위한 서비스에는 여러 유사한 방법이 있습니다. 해당 메서드를 사용하십시오:
- Players:GetPlayers()를 사용하여 현재 플레이어 개체의 테이블을 가져올 수 있습니다. 다시 말하지만, Instance:GetChildren() 대신 이를 사용하십시오.
- 마찬가지로, 를 사용하여 플레이어 개체를 제거하는 것을 감지할 수 있으며, 이는 플레이어가 제거되기 전에 발생하는 것으로, 플레이어가 제거된 후에 발생하는 대신 사용됩니다.제거 또는 제거 중에 제거될 수 있는 플레이어에 대한 정보를 저장하는 경우 중요합니다.
코드 샘플
This code sample demonstrates the creation of leaderboard stat values in Roblox's default player list UI. It creates a "Score" leaderstat that starts at 0.
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)
요약
속성
플레이어의 계정 나이(일)를 설명합니다.
모바일 장치를 사용하는 플레이어의 캐릭터가 장애물을 치면 자동으로 점프하는지 여부를 결정합니다.
플레이어의 카메라가 확대할 수 있는 최대 거리.
플레이어의 카메라가 확대할 수 있는 최소 거리.
카메라의 모드를 첫 번째 또는 세 번째 사람으로 변경합니다.
플레이어가 생성될 때 캐릭터의 모양이 로드되는지 여부를 결정합니다. 거짓이면 플레이어가 기본 모습생성됩니다.
A Model 플레이어에 의해 제어되는 플레이어에 포함된 Humanoid 신체 부위, 스크립트 및 기타 개체.
플레이어의 character에 사용되는 캐릭터 모양이 사용된 계정의 사용자 ID를 결정합니다.
기본 카메라가 카메라와 플레이어 사이의 개체를 처리하는 방법을 설정합니다.
Roblox의 데스크톱 버전을 사용할 때 플레이어의 카메라 이동 모드를 결정합니다.
Roblox의 데스크톱 버전을 사용할 때 플레이어의 캐릭터 이동 모드를 결정합니다.
플레이어가 마우스 잠금을 전환할 수 있는지 여부를 결정합니다.
터치 기기사용할 때 플레이어의 카메라 이동 모드를 결정합니다.
터치 장치를 사용할 때 플레이어의 캐릭터 이동 모드를 결정합니다.
플레이어와 관련된 UserId의 표시 이름.
플레이어가 플레이어에 의해 게임에 따라온 사용자 ID를 설명합니다.
플레이어 클라이언트 게임플레이가 현재 일시 중지되었는지 여부.
플레이어에게 인증 배지있는지 여부를 나타냅니다.
이 플레이어가 다른 휴머노이드의 체력 바를 볼 수 있는 거리를 설정합니다. 0으로 설정하면 체력 바가 표시되지 않습니다.
이 속성은 로컬 플레이어가 Roblox 계정에 설정한 지역 아이디를 표시합니다.
계정의 구성원 입력설명합니다.
이 플레이어가 다른 휴머노이드의 이름을 볼 수 있는 거리를 설정합니다. 0으로 설정하면 이름이 은폐됩니다.
플레이어가 특정 팀에 있는지 여부를 결정합니다.
부품을 중심으로 복제를 집중시킵니다.
설정되면 플레이어가 지정된 SpawnLocation에서 재생성됩니다.
플레이어가 연결된 팀을 결정합니다.
플레이어가 연결된 팀을 결정합니다.
모든 사용자 계정에 할당된 고유 식별 정수입니다.
메서드
플레이어의 캐릭터에서 모든 액세서리와 다른 캐릭터 모양 개체를 제거합니다.
문자의 머리와 지정된 Vector3 지점 사이의 거리를 반환합니다. 플레이어에 문자가 없는 경우 0을 반환합니다.
경험에 어떻게 참여하는지 설명하는 정보가 포함된 사전을 반환합니다 Player.
클라이언트가 사용하는 마우스를 반환합니다.
고립된 네트워크 대기 시간을 초 단위로 반환합니다.
플레이어의 캐릭터 모양이 로드되었는지 여부를 반환합니다.
플레이어가 구체적이고 실제 세계 신호로 확인되는지 여부를 반환합니다.
플레이어를 게임에서 강제로 분리하고, 선택적으로 메시지를 제공합니다.
플레이어의 캐릭터가 정지하거나 플레이어에 의해 중단될 때까지 지정된 방향으로 걷도록 합니다(제어사용하여).
플레이어의 계정 나이를 설정합니다.
플레이어가 필터링된 채팅을 보는지 여부를 설정하거나 일반 채팅을 보는지 여부를 설정합니다.
온라인 친구 사전을 반환합니다.
그룹에서 플레이어의 순위를 0부터 255 사이의 정수로 반환하며, 0은 멤버가 아니고 255는 그룹의 소유자입니다.
그룹에서 플레이어의 역할을 문자열로 반환하거나 플레이어가 그룹의 일부가 아니면 "게스트"로 반환합니다.
플레이어가 사용자에게 지정된 Player.UserId의 친구인지 확인합니다.
플레이어가 지정된 ID의 그룹 멤버인지 확인합니다.
플레이어를 위한 새 캐릭터를 생성하고 이전 캐릭터를 제거합니다. 또한 플레이어의 Backpack 및 PlayerGui를 지웁니다.
서버가 지정된 위치 주변의 플레이어에게 스트리밍하는 요청.
이벤트
플레이어의 캐릭터가 스폰하거나 리스폰하면 발사됩니다.
전체 모양의 Player.Character가 삽입되면 발생합니다.
플레이어의 캐릭터가 제거되기 바로 전에 해고됩니다.
Roblox가 제공한 채팅 바를 사용하여 게임 내에서 플레이어가 채팅할 때 발생합니다.
이 이벤트는 게임 엔진이 player를 빈둥대기분류한 후 약 2분 발생합니다.시간은 그 시점부터 지난 초 수입니다.
플레이어의 TeleportState가 변경될 때 발사됩니다.
속성
AccountAge
계정 나이는 플레이어의 계정이 얼마나 전에 등록되었는지를 설명하는 Player 속성입니다.스크립트에서 액세스할 수 없는 Player:SetAccountAge() 함수를 사용하여 설정됩니다.
이 속성은 조건부로 튜토리얼과 같은 새로운 Roblox 플레이어 콘텐츠를 표시하는 데 유용합니다.
코드 샘플
This code sample adds a mark to players showing about how old their account is. The mark uses a player's account age to determine if they are a New Player, Veteran Player or Regular Player.
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 값이 이 속성의 초기 상태를 결정합니다.그런 다음 이 속성은 스폰에서 속성의 값을 결정합니다.즉, 이 세 가지 속성을 사용하여 문자당, 플레이어당 및 게임당 자동 점프 동작을 설정할 수 있습니다.
코드 샘플
This code sample is meant for a TextButton. It allows the player to toggle the auto-jumping behavior while on a mobile device.
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로 증가합니다.
코드 샘플
The example demonstrates how to set a player's camera minimum and maximum zoom distance.
In this example, we set the Player.CameraMinZoomDistance and Player.CameraMaxZoomDistance to set the min and max distance in studs a player's camera can be from their character.
Note that since the example attempts to set the CameraMinZoomDistance to be greater than the CameraMaxZoomDistance, the CameraMinZoomDistance value will be decreased and set to the value of the max zoom distance.
To change the default min and max zoom distance values for a player when they first enter the game, you can change the StarterClass.Player.CameraMinZoomDistance and StarterClass.Player.CameraMaxZoomDistance properties.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMaxZoomDistance = 50
player.CameraMinZoomDistance = 75
CameraMinZoomDistance
CameraMinZoonDistance Player 속성은 기본 카메라와 캐릭터 사이의 최소 거리를 스터드로 설정합니다.
즉, 플레이어의 카메라가 확대할 수 있는 최소 거리를 제어합니다.
이 속성의 기본값은 StarterPlayer.CameraMinZoomDistance에 의해 설정됩니다.이 값이 Player.CameraMaxZoomDistance보다 높은 값으로 설정되면 CameraMaxZoomDistance로 줄어듭니다.
코드 샘플
The example demonstrates how to set a player's camera minimum and maximum zoom distance.
In this example, we set the Player.CameraMinZoomDistance and Player.CameraMaxZoomDistance to set the min and max distance in studs a player's camera can be from their character.
Note that since the example attempts to set the CameraMinZoomDistance to be greater than the CameraMaxZoomDistance, the CameraMinZoomDistance value will be decreased and set to the value of the max zoom distance.
To change the default min and max zoom distance values for a player when they first enter the game, you can change the StarterClass.Player.CameraMinZoomDistance and StarterClass.Player.CameraMaxZoomDistance properties.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMaxZoomDistance = 50
player.CameraMinZoomDistance = 75
CameraMode
카메라 모드 속성은 플레이어의 카메라 모드를 설정하며, 기본값은 제3인칭입니다.
세 번째 사람
기본 세 번째 사람 모드(Enum.CameraMode.Classic)에서 캐릭터는 카메라에서 볼 수 있습니다. 이 모드에서 기본 동작은 다음과 같습니다.
- 플레이어는 오른쪽 클릭 및 드래그(마우스), 터치 및 드래그(모바일), 보조 썸스틱(게임패드) 사용 또는 왼쪽/오른쪽 화살표(키보드) 누르기로 카메라를 주변에 회전시킬 수 있습니다.
- 플레이어가 캐릭터를 이동하면 해당 이동 방향으로 직면합니다.
- 플레이어는 자유롭게 확대하고 축소할 수 있으며, 전체 확대에서 처음 사람까지도 포함합니다.
첫 번째 사람
1인칭 모드( Enum.CameraMode.LockFirstPerson )에서 플레이어의 카메라가 전체적으로 확대됩니다.GuiButton.Modal 속성이 true로 설정되어 있고 가시적인 GUI가 없으면 마우스를 이동하거나 모바일에서 탭하여 드래그하거나 게임패드의 보조 썸스틱을 사용하면 카메라가 주변의 캐릭터를 회전합니다.
코드 샘플
This example demonstrates how to change the character's CameraMode to first person using the LockFirstPerson value of the Enum.CameraMode enum.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMode = Enum.CameraMode.LockFirstPerson
CanLoadCharacterAppearance
CanLoadCharacterAppearance Player 속성은 플레이어가 생성될 때 캐릭터의 모양이 로드되는지 여부를 결정합니다.이 속성의 기본값은 StarterPlayer.LoadPlayerAppearance에 의해 설정됩니다.
true일 경우 캐릭터는 플레이어의 Player.CharacterAppearanceId에 해당하는 플레이어의 모양을 로드합니다.
false이면 플레이어가 기본 모양으로 생성되며 - 모자, 셔츠, 바지 등이 없는 회색 캐릭터 모델
문자가 생성된 후에 속성을 설정하려고 하면 문자가 변경되지 않으며, Player:LoadCharacter()를 호출하여 새로운 모습로드해야 합니다.
코드 샘플
This example demonstrates how to disable loading a player's character appearance. Instead, the player loads as a grey model without any hats, shirts, pants, etc.
This is useful for games using custom clothing and accessories.
Note that if the character has already spawned, this change will not take affect until the player respawns or the Player:LoadCharacter() function is called.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CanLoadCharacterAppearance = false
Character
캐릭터 속성에는 경험 내에서 플레이어의 아바타를 시뮬레이션하는 데 필요한 Model, 스크립트 및 기타 개체를 포함하는 Humanoid 참조가 포함되어 있습니다모델은 Workspace 에 부모로 지정되지만 이동될 수 있습니다.Players.CharacterAutoLoads 가 true 로 자동으로 로드되고, 그렇지 않으면 Player:LoadCharacter() 을 사용하여 수동으로 로드할 수 있습니다.
처음에는 이 속성이 nil이고 플레이어의 캐릭터가 처음 생성될 때 설정됩니다.Player.CharacterAdded 이벤트를 사용하여 플레이어의 캐릭터가 올바르게 로드되는 시기를 감지하고, Player.CharacterRemoving 이벤트를 사용하여 캐릭터가 소멸될 예정인지 감지합니다.이 속성에서 Object:GetPropertyChangedSignal()를 사용하지 않도록 주의하십시오.
클론된 또는 또는 플레이어의 또는 속으로 복제된 것은 오래된 캐릭터 모델이 교체되기 전에 종종 실행되므로 이전 모델의 속성을 참조할 수 있습니다.따라서, 아래의 또는 에서는 예를 들어, 문자 의 부모가 사용하기 전에 아닌지 확인하는 것이 좋습니다.
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기본적으로 이 속성은 Player.UserId , 즉 Roblox 웹사이트에서 생성한 플레이어의 아바타를 사용하는 것입니다.
이 속성을 다른 계정의 사용자 ID로 변경하면 플레이어가 해당 계정의 모양(모자, 셔츠, 바지 등)으로 생성됩니다.
게임은 또한 플레이어의 캐릭터 모양이 게임에 로드되는지 여부를 변경하여 StarterPlayer.LoadCharacterAppearance 속성을 변경하여 플레이어의 캐릭터 모양이 게임에 로드되는지 여부를 전환할 수 있습니다.
코드 샘플
This code sample allows players to chat "/disguise xyz", where xyz is a user ID or username, and they will respawn appearing like that account's avatar. Try typing "/disguise 261" or "/disguise Shedletsky"!
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 (서버에서 사용하여 설정해야 함)를 사용하여 설정할 수 없습니다.This property cannot be set using a (it must be set on the server using a Script ).
이 속성의 기본값은 StarterPlayer.DevComputerCameraMovementMode에 의해 결정됩니다.
이 속성 이름에서 "컴퓨터"라는 단어는 TouchEnabled 및 GamepadEnabled 없는 장치를 가리킵니다.
사용자 선택 으로 설정되면 Roblox 게임 설정에서 어떤 컨트롤 모드( 스크립트 가능 제외)를 선택할 수 있습니다.일반적으로 플레이어가 접근성을 최대화하기 위해 컨트롤 모드를 선택할 수 있도록 허용하는 것이 좋습니다.
이 속성을 스크립트 가능 으로 설정하여 사용자 지정 컨트롤 스키마를 만들 수 있습니다.
이 속성은 터치 활성화된 기기사용하는 플레이어에 영향을 주지 않습니다. 대신 Player.DevTouchCameraMode를 참조하십시오.
코드 샘플
The example demonstrates how to set a player's camera movement mode for players on a computer.
In this example, we set the camera movement mode to Classic via the Enum.DevComputerCameraMovementMode enum. This means that the camera of players on touch enabled devices will track the player but will not automatically rotate if the player walks left or right.
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 (서버에서 사용하여 설정해야 함)를 사용하여 설정할 수 없습니다.This property cannot be set using a (it must be set on the server using a Script ).
이 속성의 기본값은 StarterPlayer.DevComputerMovementMode에 의해 결정됩니다.
이 속성 이름의 "컴퓨터" 단어는 비-TouchEnabled 장치를 가리킵니다.
사용자 선택 으로 설정되면 Roblox 게임 설정에서 어떤 컨트롤 모드( 스크립트 가능 제외)를 선택할 수 있습니다.일반적으로 플레이어가 접근성을 최대화하기 위해 컨트롤 모드를 선택할 수 있도록 허용하는 것이 좋습니다.
이 속성을 스크립트 가능 으로 설정하여 사용자 지정 컨트롤 스키마를 만들 수 있습니다.
이 속성은 터치 활성화된 기기사용하는 플레이어에 영향을 주지 않습니다. 대신 Player.DevTouchMovementMode를 참조하십시오.
코드 샘플
Demonstrates how to set the movement mode for players on computers using the Player.DevComputerMovementMode property.
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 를 누르면 잠금을 전환할 수 있는지 여부를 결정합니다.플레이어는 Roblox의 게임 설정에서 마우스 잠금 스위치를 비활성화할 수 있습니다.기본적으로 이 속성은 StarterPlayer.EnableMouseLockOption의 값으로 설정됩니다.이는 Script를 사용하여 런타임에 서버 측에서 설정할 수 있습니다.클라이언트 측에서 설정할 수 없습니다.
마우스 잠금이 활성화되면 플레이어의 커서가 화면 중앙에 잠깁니다.마우스를 이동하면 플레이어의 character 주위에 카메라가 회전하고 캐릭터는 camera와 동일한 방향을 향합니다.또한 플레이어의 캐릭터의 오른쪽 어깨 위에 카메라 뷰를 오프셋합니다.
쉬프트락 관련 API가 사라지는 과정에 있으므로 마우스를 잠그기 위해 UserInputService.MouseBehavior 대신 사용하는 것이 좋습니다.
코드 샘플
This code sample demonstrates how to toggle whether mouse lock is available to a player using a chat command. When a player types "mouselock", their ability to toggle mouse lock is toggled. Note that this does not toggle the actual state of mouse lock; rather, it changes whether a player is able to toggle it themselves.
This code can be run by pasting it into a Script within ServerScriptService.
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를 참조하십시오.
코드 샘플
The example demonstrates how to set a player's camera movement mode.
In this example, we set the camera movement mode to Classic via the Enum.DevTouchCameraMovementMode enum. This means that the camera of players on touch enabled devices will track the player but will not automatically rotate if the player walks left or right.
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를 참조하십시오.
코드 샘플
The example demonstrates how to set the movement mode for players on touch enabled devices.
In this example, we set the movement mode to Thumbstick via the Enum.DevTouchMovementMode enum. This means that players on touch enabled devices are able to move via a virtual thumbstick on their screen.
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
DisplayName는 Player 개체와 관련된 인증된 사용자의 표시 이름을 포함하는 속성입니다.The is a property that contains the display name of the authenticated user associated with the Player object.사용자 이름과 달리, 표시 이름은 플레이어가 다른 사람에게 표시하는 고유하지 않은 이름입니다.Roblox 사용자가 하나를 선택하지 않았으면 속성은 Name 속성과 동일하게 읽습니다.
참고:
- 표시 이름이 고유하지 않기 때문에 단일 인스턴스에서 두 플레이어가 동일한 이름을 가질 수 있습니다.플레이어에 대한 전역적으로 고유한 식별자가 필요한 경우 Player.UserId(정적) 또는 Player.Name(현재 사용자 이름) 대신 사용하십시오.
- Player.LoadCharacter 또는 Roblox 엔진으로 생성된 캐릭터는 속성 Humanoid.DisplayName 이 속성 Player.DisplayName 에 할당됩니다.
- 표시 이름에는 문자 코드 문자가 문자열에 있을 수 있습니다. 문자 코드 문자로 작업하는 방법에 대한 자세한 내용은 UTF-8에 참조하십시오.
FollowUserId
FollowUserId는 플레이어가 게임으로 이동한 사용자의 Player 속성을 포함하는 속성입니다.The FollowUserId is a property that contains the Player.UserId of the user that a player followed into the game.플레이어가 게임에 누구에게도 따르지 않았다면 이 속성은 0이 됩니다.이 속성은 다른 플레이어가 게임에 따라온 플레이어를 알리는 데 유용합니다.
이 사용자 ID와 Players:GetNameFromUserIdAsync() 함수를 사용하여 플레이어의 이름을 따라갈 수 있습니다.
코드 샘플
This code sample alerts players if a new player follows the local player into the game. Place this in a LocalScript in StarterPlayerScripts.
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
게임플레이 일시 중지 속성은 플레이어가 현재 활성화된 장소에서 일시 중지 상태에 있는지 여부를 나타냅니다.클라이언트에 설정되지만 서버에 복제됩니다.일시 중지 상태를 확인하려면 이 속성을 사용할 수 있습니다.
참조하세요:
- Workspace.StreamingEnabled 콘텐츠 스트리밍을 활성화할지 여부를 제어하는 것
- Workspace.StreamingIntegrityMode 및 Enum.StreamingIntegrityMode 게임플레이가 일시 중지된 시기에 대한 자세한 내용.
HealthDisplayDistance
HealthDisplayDistance Player 속성은 이 플레이어가 다른 건강 바를 볼 수 있는 스터드의 거리를 설정합니다.Humanoid0으로 설정하면 상태 바가 표시되지 않습니다.이 속성은 기본적으로 StarterPlayer.HealthDisplayDistance로 설정됩니다.
인간형의 체력바가 표시되는 경우, Humanoid.DisplayDistanceType를 사용하여 표시 유형을 설정할 수 있습니다.
코드 샘플
This example demonstrates how to hide other Humanoid's (Player and NPC) health bars and names.
This is done by setting the player's Player.HealthDisplayDistance and Player.NameDisplayDistance properties to 0.
If you would like to display health bars and names, you set the properties to a value greater than 0. For instance, setting the properties to 100 means that the player will see other player's health and names up to 100 studs away.
To modify the default values for players, you can change the values of the StarterClass.Player.HealthDisplayDistance and StarterClass.Player.NameDisplayDistance properties.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.HealthDisplayDistance = 0
player.NameDisplayDistance = 0
LocaleId
로캘 ID Player 속성은 로컬 플레이어가 Roblox 계정에 설정한 로캘 ID를 표시합니다.로캘에 대해 두 문자 코드(예: "en-us")가 들어있는 문자열을 보유합니다(예: "en-us").
이를 사용하여 게임의 플레이어 기반의 지리적 인구 통계를 결정할 수 있으며, 경험 내 콘텐츠의 자동 번역(보기 GuiBase2d.AutoLocalize)에 사용될 로캘입니다.이 속성을 통해 서버에서 플레이어의 로캘에 액세스할 수 있습니다.
또한 참조하십시오 LocalizationService.RobloxLocaleId , 내부 콘텐츠를 지역화하는 데 사용되는 로캘 ID.Roblox가 아직 로컬 플레이어의 설정 로캘을 내부적으로 지원하지 않을 때 다른 값이 됩니다.
코드 샘플
This example demonstrates how to check the locale of a local player using the Player.LocaleId property. It prints a string with the two letter locale code for the locale of the local player.
For instance, if the player's local is within the US, the locale will be:
en-us
local Players = game:GetService("Players")
local player = Players.LocalPlayer
print(player.LocaleId)
MembershipType
이 속성은 구성원 자격을 결정하기 위해서만 읽을 수 있으며(다른 구성원 입력설정할 수는 없음) 다른 구성원 유형으로 설정할 수는 없습니다.계정의 구성원 입력열거형을 Enum.MembershipType 보유합니다.
코드 샘플
The following example checks whether a player has Premium membership.
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 속성은 이 플레이어가 다른 이름을 볼 수 있는 스터드 거리를 설정합니다.속성이 0으로 설정되면 이름이 숨겨집니다.이 속성은 기본적으로 StarterPlayer.NameDisplayDistance로 설정됩니다.
인간형의 체력바가 표시되는 경우, Humanoid.DisplayDistanceType를 사용하여 표시 유형을 설정할 수 있습니다.
코드 샘플
This example demonstrates how to hide other Humanoid's (Player and NPC) health bars and names.
This is done by setting the player's Player.HealthDisplayDistance and Player.NameDisplayDistance properties to 0.
If you would like to display health bars and names, you set the properties to a value greater than 0. For instance, setting the properties to 100 means that the player will see other player's health and names up to 100 studs away.
To modify the default values for players, you can change the values of the StarterClass.Player.HealthDisplayDistance and StarterClass.Player.NameDisplayDistance properties.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.HealthDisplayDistance = 0
player.NameDisplayDistance = 0
Neutral
중립 속성은 플레이어가 특정 팀에 있는지 여부를 결정합니다.
코드 샘플
This example checks if a player is neutral. If the player is neutral, the game prints:
Player is neutral!
If the player is not neutral, the game prints:
Player is not neutral!
Note: Although this example prints the value of the local player's neutral property, you can change the example to get the value for any player.
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 로만 설정해야 합니다.이 속성은 부품의 네트워크 소유권을 변경하거나 업데이트하지 않습니다.
코드 샘플
This example creates a new BasePart and sets the Player's Player.ReplicationFocus to that part.
This demonstrates the functionality of the ReplicationFocus property. You can easily change the part that the focus is set to to change the replication focus.
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를 수동으로 이동합니다.
코드 샘플
This code sample will set the player to always respawn from the last SpawnLocation they touched. New players will respawn from the SpawnLocation named 'FirstSpawn' until they touch a different SpawnLocation.
This is an alternative to using the AllowTeamChangeOnTouch property to switch SpawnLocations and does not require Teams.
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
팀 속성은 서비스 내의 개체에 대한 참조입니다.플레이어가 속한 팀을 결정합니다; 만약 Player 이 팀에 없거나 무효한 Player.TeamColor 을 가지고 있으면, 이 속성은 nil 입니다.이 속성이 설정되면 플레이어가 Team 와 함께 가입하고 관련 팀에서 Team.PlayerAdded 이벤트가 발생합니다.마찬가지로, Team.PlayerRemoved 속성이 특정 Team에서 제거되면 화재가 발생합니다.
코드 샘플
This code sample, although lengthy, is quite simple: detect when a player chats /play, then put them on the "Playing" team. When they die, move them back to the "Spectating" 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)
This code sample allows any player to chat "/jointeam " where is the name of a team. It uses string manipulation using string.sub and string.lower to make the command case-insensitive and allow for partial matches. For example, "/jointeam red" will match the team "Red Robins".
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
팀 색상 속성은 팀의 Team.TeamColor에 따라 플레이어가 어떤 팀과 연결되는지 결정합니다.이 속성을 변경하면 변경된 팀에 따라 Player.Team 가 변경되며, 해당 팀의 BrickColor 에 동일한 Team.TeamColor 가 있는 경우에만 변경됩니다.팀 개체에 연결된 팀 색상이 없으면 플레이어가 팀에 연결되지 않습니다.
이 속성을 사용하는 대신 각각의 Player.Team에 Team를 설정하는 것이 종종 더 나은 아이디어입니다.이 속성을 자주 설정하면 여러 스크립트에서 특정 팀에 대해 동일한 BrickColor 값이 반복되는 경우가 많습니다; DRY(자신을 반복하지 마십시오) 원칙을 따르는 경우 피하고 싶은 것입니다.
코드 샘플
This code sample, although lengthy, is quite simple: detect when a player chats /play, then put them on the "Playing" team. When they die, move them back to the "Spectating" 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)
ThirdPartyTextChatRestrictionStatus
UserId
사용자 ID는 Roblox의 모든 사용자 계정을 고유하고 일관되게 식별하는 읽기 전용 정수를 포함하는 속성입니다.플레이어의 Instance.Name 와는 달리, 사용자의 현재 사용자 이름에 따라 변경될 수 있는 것과는 달리, 이 값은 동일한 계정에 대해 결코 변경되지 않습니다.
이 속성은 GlobalDataStores를 사용하여 플레이어 데이터를 저장/로드할 때 필수입니다.각 플레이어가 고유한 키를 갖도록 플레이어의 사용자 ID를 데이터 저장소 키로 사용합니다.
코드 샘플
The below example would print the UserId of every user who entered a game.
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
The following code sample gives an example of a 'met the creator' badge system. This script will award a specified badge (BADGE_ID) to anyone who is in a server at the same time as the user associated with OWNER_ID.
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)
This code sample retrieves a player's saved gold from a data store and puts the returned value onto the leaderboard. Note that this sample does not save players' gold — it only loads it.
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
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을 반환합니다.
이는 게임의 플레이어와 다른 개체나 위치 사이의 거리를 결정할 때 유용합니다.
두 비플레이어 인스턴스 또는 위치 사이의 거리를 결정하려는 경우 팔로잉사용할 수 있습니다.
local distance = (position1 - position2).Magnitude
매개 변수
플레이어의 거리를 측정하는 위치입니다.
반환
플레이어와 위치 사이의 스터드 거리.
코드 샘플
This example demonstrates how to measure the distance between a player's Player.Character and another location.
This code will print the distance of each player's character from the origin (0, 0, 0):
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>플레이어가 순간이동한 경험의 Class.DataModel.GameId.플레이어가 현재 경험으로 순간이동하고 서버가 순간이동 함수를 호출하는 경우에만 표시됩니다.</td></tr><tr><th>소스 장소 ID</th><td>번호</td><td>플레이어가 순간이동한 장소의 Class.DataModel.PlaceId .플레이어가 현재 장소로 순간이동하고 서버가 순간이동 함수를 호출하는 경우에만 표시됩니다.</td></tr><tr><th>플레이어ID에 의한 참조</th><td>번호</td><td>현재 플레이어를 경험에 초대한 플레이어의 <code>Class.Player.UserId</code>.이 데이터를 사용하여 참조자를 식별하고 보상 논리를 트리거합니다.</td></tr><tr><th>멤버</th><td>배열</td><td>사용자가 <code>플레이어</code>와 함께 순간이동한 수 <code>Class.Player.UserId</code>의 숫자가 포함된 배열.플레이어가 그룹의 일부로 순간이동한 경우에만 표시됩니다.</td></tr><tr><th>텔레포트 데이터</th><td>변형</td><td>원래 순간 이동에 지정된 <code>teleportData</code>를 반영합니다.플레이어가 순간이동하는 서버 간의 정보 공유에 유용합니다.<code>teleportData</code>가 지정되고 서버가 전송 함수를 호출하는 경우에만 표시됩니다.</td></tr><tr><th>런처 데이터</th><td>문자열</td><td><a href="../../../production/promotion/deeplinks.md">깊은 링크</a> URL 또는 <code>Class.ExperienceInviteOptions.LaunchData</code>에 지정된 런처 데이터를 포함하는 일반 또는 JSON 인코딩된 문자열</td></tr><tr><th>게임JoinContext</th><td>사전</td><td>게임 조인의 컨텍스트에 따라 관련 정보가 포함된 사전입니다. 다음 키가 포함되어 있습니다:<ul><li><code>JoinSource</code> : <code>Enum.JoinSource</code></li><li><code>ItemType</code> : 선택적 <code>Enum.AvatarItemType</code></li><li><code>AssetId</code> : 선택적 <code>string</code> ></li><li><code>OutfitId</code> : 선택적 <code>string</code> ></li><li><code>AssetType</code> : 선택적 <code>Enum.AssetType</code> ></li></ul></td></tr></tbody>
키 |
---|
GetJoinData 및 TeleportData 받기
서버가 플레이어의 텔레포트시작하면 이 메서드가 반환하는 사전에는 플레이어의 순간이동 데이터가 포함됩니다.Player:GetJoinData() 메서드는 서버에서 순간이동 데이터를 가져오는 데만 사용할 수 있습니다.클라이언트에서 데이터를 가져오려면 TeleportService:GetLocalPlayerTeleportData()를 사용하십시오.
TeleportService:GetLocalPlayerTeleportData() 와는 달리, Player:GetJoinData() 는 다음 보안 요건을 충족하는 순간 이동 데이터만 제공합니다:
- 지난 48시간 동안 Roblox 서버에서 보낸 것임이 보장됩니다.
- 이 Player 로 전송되었음이 보장됩니다.
- SourcePlaceId 및 SourceGameId 는 데이터가 전송된 장소와 우주가 보장되어 있습니다.즉, 승인된 플레이스순간이동 데이터가 왔는지 확인할 수 있습니다.
이 데이터가 클라이언트에 의해 전송되기 때문에 악용자에 의해 여전히 악용될 수 있습니다.플레이어 통화와 같은 민감한 데이터는 메모리 저장소와 같은 보안 솔루션을 통해 전송해야 합니다.
반환
PlaceId 및 UserId 값이 포함된 사전(참조: 설명의 표)
코드 샘플
The following example tracks sources of traffic for analytics. By creating URLs with unique launch data for each social platform, you can determine the most popular traffic sources. The sample checks the source against a list of possible samples and discards any invalid sources because users can modify the launch data.
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)
The following example generates a URL with the user's ID used as launch data. It then displays the URL in a read-only text box that makes it easy for the user to copy and share the link with their friends. When a user joins the game using a referral link, you can use the launch data to reward the referrer.
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)
The following example is a function that converts a table into a string you can use as launch data. The provided data is JSON encoded, checked for valid character length, and escaped with percent signs.
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
The following example attempts to decode launch data, using pcall to prevent an error in case the data is corrupt.
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)
The following code sample is an example of how teleport data can be retrieved on the server using Player:GetJoinData(). This code, when ran in a Script in ServerScriptService, will listen for new Player|Players joining the game. When they join it will retrieve their teleport data (verifying it came from a valid place) to find their current level.
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월의 업데이트 이후로 마우스의 아이콘을 이 방법으로 설정할 수 있습니다.
반환
코드 샘플
The below example will print:
Button 1 is down
whenever the Players.LocalPlayer left clicks.
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 에 반환합니다.“핑”은 클라이언트에서 서버로 데이터를 전송하고 다시 돌아오는 데 걸리는 시간의 측정입니다.데이터 디세리알화나 처리가 관련되지 않습니다.
클라이언트 측 LocalScripts에 대해서는 이 함수를 Players.LocalPlayer에서만 호출할 수 있습니다.이 함수는 높은 네트워크 대기 시간 시나리오에서 발생하는 문제를 식별하고 디버그하는 데 유용합니다.발사체의 던지기 애니메이션 속도를 조정하여 지연을 마스킹하는 것과 같이 유용합니다.
반환
HasAppearanceLoaded
HasAppearanceLoaded Player 함수는 플레이어의 Player.Character 모양이 로드되었는지 여부를 반환합니다.
플레이어의 모양에는 플레이어의 Shirt , Pants 및 Accessories 등의 아이템이 포함됩니다.
이는 플레이어의 모양이 처음 게임에 참여한 후 로드되었는지 여부를 결정하는 데 유용하며, Players.PlayerAdded 이벤트를 사용하여 추적할 수 있습니다.
반환
플레이어의 캐릭터가 로드되었는지 여부를 나타내는 부울입니다.
코드 샘플
This example prints the result of Player:HasAppearanceLoaded() after a player joins the game until the player's appearance has loaded.
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 전화 번호 또는 정부 ID 확인이 포함되지만 제한되지는 않습니다.
구현할 때 IsVerified , 실수로 모든 미확인 사용자를 차단하지 않도록 주의하십시오.
방법은 백엔드 서버에서만 호출할 수 있다는 점에 유의하십시오.클라이언트 측에서 호출하면 오류가 발생합니다.또한 이 메서드는 항상 Studio에서 false를 반환합니다.
반환
플레이어가 확인되었는지를 나타내는 부울입니다.
코드 샘플
The following example prints "true" if the player is verified.
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에 호출하면 기본 메시지를 제공된 문자열로 바꿉니다.
이 메서드를 사용할 때 LocalScript 에서, 로컬 사용자의 클라이언트만 킥될 수 있습니다.
매개 변수
사용자를 킥할 때 표시할 메시지.
반환
Move
이동 Player 함수는 플레이어의 캐릭터가 플레이어(그들의 제어사용하여)에 의해 중지되거나 중단될 때까지 지정된 방향으로 걷도록 합니다.
이는 맵 주변을 이동하는 NPC Humanoids를 스크립팅할 때 유용합니다 - 하지만 실제 플레이어의 입력으로 제어되지 않습니다.
함수의 두 번째 인수가 제공된 Vector3 가 플레이어를 세계 좌표로 이동시키는지(false) 아니면 플레이어의 Camera(true)에 이동시키는지를 나타냅니다.
매개 변수
플레이어가 이동해야 하는 Vector3 방향.
플레이어가 플레이어의 카메라에 대해 이동할지 여부를 나타내는 부울입니다.
반환
코드 샘플
Demonstrates moving a player relative to their camera's position using Player:Move().
The script first waits for the player's Character and Humanoid to load, as both are required before calling Player:Move(). Otherwise a warning will display in the Output.
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 속성을 설정하는 데 사용됩니다.
이는 계정에서 플레이어의 나이를 설정하지 않지만, 계정 자체가 처음 생성된 시점과 비교하여 나이를 설정합니다.
매개 변수
계정의 날짜 기준 나이.
반환
코드 샘플
This example demonstrates how the Player:SetAccountAge() function would be used if it was accessible. It sets the local player's account age to 100 days.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player:SetAccountAge(100)
This code sample adds a mark to players showing about how old their account is. The mark uses a player's account age to determine if they are a New Player, Veteran Player or Regular Player.
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>Online 상태 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 모바일 웹사이트 > 모바일 게임 > 9 스튜디오 > 친구의 마지막 위치의 위치 유형: 마지막 위치의 위치 유형: 모바일 웹사이트 친구의 마지막 위치의 위치 유형: 모바일 웹사이트의 마지막 위치의 위치 유형: 모바일 웹사이트의 친구의 마지막 위치: 모바일 웹사이트 모바일 모바일 위치: 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모바일 모일 모일 모일 모바일 모일 모바일 모바일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모일 모</td></tr></tbody>
이름 |
---|
매개 변수
반환할 온라인 친구 최대 수.
반환
온라인 친구 사전(위의 표 참조).
코드 샘플
This example demonstrates how to get a dictionary of a player's online friends. It returns the maximum number of friends specified by the argument, or 200 if an argument is not provided.
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 메서드를 여러 번 호출하면 메서드가 처음 호출될 때와 동일한 결과가 나타납니다.캐싱 행동은 피어 기반입니다: 서버는 클라이언트와 동일한 캐시를 공유하지 않습니다.
매개 변수
지정된 그룹의 groupId입니다.
반환
그룹에서 플레이어의 순위.
코드 샘플
The code below will check if a player that has entered the game has a rank equal to 255, in a group with an ID of 2. If they are, it will print "Player is the owner of the group, 'LOL'!", otherwise "Player is NOT the owner of the group, 'LOL'!" will be printed to the output.
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.
반환
지정된 그룹에서 플레이어의 역할, 또는 게스트 플레이어가 멤버가 아닌 경우.
코드 샘플
The code below will print the name of the rank that the player is currently a part of, in a specific group. In this instance we're checking what rank the player is within a group which has a group ID of 2.
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.
반환
플레이어가 지정된 사용자의 친구인지를 나타내는 부울입니다.
코드 샘플
The below example would print whether or not a recently added player is friends with Gordonrox24.
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와 동일한 결과를 제공합니다.캐싱 행동은 피어 기반입니다: 서버는 클라이언트와 동일한 캐시를 공유하지 않습니다.
매개 변수
지정된 그룹의 그룹 ID.
반환
플레이어가 지정된 그룹에 있는지를 나타내는 부울입니다.
코드 샘플
The below example will print "Player is in the Roblox Fan club!" if the newly added player is in the group with a groupId of 7.
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.CharacterAdded 발사
- Player.Changed는 "캐릭터"라는 값으로 발생합니다
- 캐릭터 모양 초기화
- Player.CharacterAppearanceLoaded 발사
- Character.Parent가 DataModel로 설정
- 캐릭터 리그 빌드 및 캐릭터 크기 조정
- 캐릭터가 스폰 위치로 이동
- 로드캐릭터 반환
반환
코드 샘플
This script turns off auto-loading and simulates character respawning.
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 이벤트가 발생한 후에야 동일한 플레이어에 대해 함수를 다시 호출하는 것이 좋지 않습니다.
참조하세요:
- 인간형 설명 시스템 , 인간형 설명 시스템을 보다 자세히 설명하고 여러 스크립트 예제를 제공하는 기사
매개 변수
신체 부위/색상, 신체 크기 조정, 액세서리, 복장및 애니메이션과 같은 특성을 포함하는 A HumanoidDescription 로드된 캐릭터에 장착될 예정인 캐릭터.
반환
코드 샘플
To create a HumanoidDescription and then spawn a character with that description applied, add a Script (not a LocalScript) to the workspace and add this code to it.
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
인스턴스 스트리밍이 활성화된 경험에서는 서버가 지정된 X , Y , Z 위치의 플레이어 영역(부품과 지형)으로 스트림하는 요청이 3D 세계에서 수행됩니다.경험이 플레이어의 CFrame가 가까운 미래에 지정된 위치로 설정될 것임을 알고 있으면 유용합니다.이 호출로 위치를 제공하지 않으면 플레이어가 대상에 대한 콘텐츠를 스트리밍하지 않아 스트리밍 일시 중지 또는 다른 원하지 않는 행동이 발생할 수 있습니다.
이 호출의 효과는 일시적이며 지정된 위치 주변에 스트리밍될 내용에 대한 보장은 없습니다.클라이언트 메모리 제한 및 네트워크 조건이 클라이언트에서 사용할 수 있는 기능에 영향을 줄 수 있습니다.
사용 주의
지역 주위의 스트리밍 요청은 클라이언트의 네트워크 대역폭, 메모리 제한 및 기타 요인에 영향을 받기 때문에 요청이 완료되면 콘텐츠가 존재할 것이라는 보장은 아닙니다 스트리밍 .
매개 변수
반환
이벤트
CharacterAdded
문자 추가 이벤트는 플레이어의 캐릭터가 생성(또는 재생)될 때 발생합니다.이 이벤트는 설정 Player.Character 을 비-nil 값으로 설정하거나 호출 Player:LoadCharacter() 을 호출하여 문자가 Workspace 에 부모가 되기 전에 발생합니다.
이는 플레이어의 캐릭터가 제거될 직전에 발생하는 Player.CharacterRemoving 이벤트와 함께 사용할 수 있으며, 일반적으로 사망 후에 발생합니다.따라서 이러한 이벤트 둘 다 플레이어가 죽은 후 플레이스재생성하면 여러 번 발생할 수 있습니다.플레이어가 게임에 참여하거나 게임을 떠날 때를 감지하려면 Players.PlayerAdded 및 Players.PlayerRemoving 이벤트를 대신 사용하십시오.
이 이벤트가 발생할 때 Humanoid 및 기본 신체 부위(머리, 몸통, 팔과 다리)가 존재하지만 Hats , Shirts , Pants 와 같은 의류 아이템이 캐릭터에 추가되기까지 몇 초가 걸릴 수 있습니다.추가된 문자에 연결 Instance.ChildAdded 이를 감지하거나 문자가 모든 장비가 갖추어졌는지 확인하기 위해 Player.CharacterAppearanceLoaded 이벤트를 기다리세요.
매개 변수
생성되거나 재생성된 캐릭터의 인스턴스.
코드 샘플
This code sample demonstrates the usage of Players.PlayerAdded, Player.CharacterAdded and Player.CharacterRemoving in order to detect the spawning and despawning of players' characters. You can use this as a boilerplate script to make changes to players' characters as they spawn, such as changing Humanoid.WalkSpeed.
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)
This code sample will cause players to respawn at the same place they died. It does this by keeping track of where the player despawned using Player.CharacterRemoving. Note that the player's location is saved on-despawn, not on-death. This can be problematic if the player falls off a ledge and dies due to Workspace.FallenPartsDestroyHeight - their respawn position won't be saved in this case.
It's also important to note the need to "forget" the location of players who leave the game. We use Instance.ChildRemoved on Players instead of Players.PlayerRemoving. This is because PlayerRemoving fires before CharacterRemoving - and we need to make sure we don't forget the player's respawn location then immediately remember a new one (this is a memory leak; potentially many players could visit, respawn and leave). So, we use ChildRemoved on Players so the event fires after the character is removed.
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)
This code sample automatically removes Accessory objects like hats from the Player's character when they respawn. Warning: this includes hair, so this script may cause acute baldness.
When the Character() is added, we wait for RunService.Stepped to fire once (using the wait function of events). This is so the accessory removal logic runs one frame after the character spawns. A warning can appear if you delete accessories too quickly after the player spawns, so waiting one frame will avoid that.
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에 삽입될 때 발생합니다.
이 이벤트는 서버에서만 발생합니다.
이 이벤트의 한 사용은 액세서리를 삭제하기 전에 모든 액세서리가 로드되었는지 확인하는 것입니다. 아래에서 이 예제를 참조하십시오.
매개 변수
The Class.Player.Character``Class.Model .
코드 샘플
This code sample will wait for accessories to fully load, print out how many there are, and then destroy them all.
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 이벤트를 사용하십시오.
매개 변수
제거되는 캐릭터의 인스턴스.
코드 샘플
This example prints the name of the character being removed, followed by "has died".
For instance, if Shedletsky's character was to die in-game, "Shedletsky has died." would be printed.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterRemoving:Connect(function(character)
print(character.Name .. " has died.")
end)
end)
Chatted
채팅 이벤트는 Player 가 메시지를 입력하고 Roblox의 제공된 채팅 바에서 엔터를 누르면 발생합니다.기본 채팅 스크립트에서 일부 Luau 바인딩을 사용하여 이 작업이 수행됩니다.StarterGui:SetCoreGuiEnabled()를 사용하여 채팅을 방지하고 Chat Enum.CoreGuiType을 비활성화하여 플레이어가 채팅하는 것을 방지할 수 있습니다.
채팅 명령
이 이벤트와 일부 문자열 조작 함수(예: string.sub() 및 string.lower() )를 사용하여 플레이어 이름과 같은 인수를 사용하여 채팅 명령을 만들 수 있습니다.일반적으로 명령은 접두사가 붙은 형태로 나타납니다(예: heal PlayerName).문자열에서 접두사를 확인하려면 메시지에서 string.sub()를 사용하여 메시지의 부분 문자열을 확인하십시오: string.sub(message, 1, 6) == "/heal " (공백 포함 참고).그런 다음, string.sub()에서 명령의 나머지를 다시 추출하십시오: string.sub(message, 7)는 플레이어 이름과 동일할 것입니다.해당 플레이어가 존재하는지 확인하고, 존재하는 경우 명령의 작업(이 예제에서는 치유)을 수행합니다.채팅 명령의 예제에 대한 코드 샘플을 확인합니다.
필터링
이 이벤트로 발사된 메시지 텍스트는 필터링되지 않음 입니다.채팅과 같은 플레이어 입력을 다른 플레이어에게 어떤 형태로든 표시하는 경우 Chat:FilterStringAsync()를 사용하여 필터링해야 합니다.자체 채팅 시스템을 만들 때 이 점을 염두에 두십시오; 게임이 채팅을 적절하게 필터링하지 않으면 조정 조치가 취해질 수 있습니다.
매개 변수
플레이어가 채팅에서 입력한 메시지의 내용.
사용되지 않음. 위스퍼 메시지의 경우, 이것은 채팅 메시지의 의도된 대상이었던 플레이어였습니다.
코드 샘플
Setting chatted for all players. There is an easy way to make the Chatted event registered on all players. Simply use the Players.PlayerAdded event in combination with this event.
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)
This code sample, although lengthy, is quite simple: detect when a player chats /play, then put them on the "Playing" team. When they die, move them back to the "Spectating" 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)
This code sample allows any player to chat "/jointeam " where is the name of a team. It uses string manipulation using string.sub and string.lower to make the command case-insensitive and allow for partial matches. For example, "/jointeam red" will match the team "Red Robins".
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의 발생과 상관 관계를 시도하십시오.
매개 변수
플레이어가 빈둥대기상태로 있었던 시간(초).
코드 샘플
Prints how long a player has been idle for.
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() 사용된 경우 순간이동할 스폰의 이름.
코드 샘플
This example prints which stage of a teleport a player is at, as well as printing if the teleport was a failure.
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)