요약
속성
메서드
이벤트
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
코드 샘플
1인칭 플레이
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
코드 샘플
플레이어.파티아이디
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()
--> BodyColors 캐릭터에서 삭제됨
--> ShirtGraphic 캐릭터에서 삭제됨
--> Shirt 캐릭터에서 삭제됨
--> Pants 캐릭터에서 삭제됨
--> CharacterMesh 캐릭터에서 삭제됨
--> Hat 캐릭터에서 삭제됨
--> Shirt 캐릭터에서 삭제됨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)
-- 액세서리를 제거하기 전에 잠시 기다려서
-- "예기치 않게 ___의 부모를 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(("%s의 %d 개 액세서리를 제거합니다."):format(player.Name, numAccessories))
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(
매개 변수
코드 샘플
플레이어.온텔레포트
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)