SocialService

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음
서비스
복제되지 않음

SocialService 는 Roblox 플랫폼에서 만들어진 관계에 영향을 주는 소셜 기능을 용이하게 합니다.주요 용도는 플레이어에게 초대 프롬프트와 전화 부록을 표시하여 친구에게 초대 요청을 보낼 수 있도록 하는 것입니다. 즉, PromptGameInvite()PromptPhoneBook()를 통해 각각 보낼 수 있습니다.이러한 요청이 발생할 때 신호를 활용할 수 있습니다.

요약

메서드

이벤트

콜백

속성

메서드

GetPlayersByPartyId

Instances

현재 연결된 모든 Player 개체의 테이블을 반환하여 Player.PartyId 속성이 제공된 partyId와 일치합니다.이 메서드는 Players:GetPlayers()과 유사하게 동작하지만 결과를 필터링하여 지정된 파티에 속하는 플레이어만 포함하도록 합니다.

이 서비스는 Roblox Studio에서 플레이테스트 중에 작동하지 않으므로, 경험의 측면을 테스트하려면 경험을 게시하고 Roblox 응용 프로그램에서 플레이해야 합니다.

매개 변수

partyId: string
기본값: ""

반환

Instances

Player 속성이 전달된 Player.PartyId에 일치하는 개체의 테이블, 속성이 전달된 partyId에 일치하는 개체의 테이블

코드 샘플

The following example listens for when a player joins the experience. If the player is part of a party, it uses SocialService:GetPlayersByPartyId() to retrieve all players in the same party who are currently connected to the server. It then outputs the name of each party member.

SocialService:GetPlayersByPartyId()

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local partyId = player.PartyId
if partyId ~= "" then
local partyPlayers: { Player } = SocialService:GetPlayersByPartyId(partyId)
for _, partyMember in partyPlayers do
print("Party Member: " .. partyMember.Name)
end
else
warn("Player is not in a party")
end
end)

This code sample demonstrates how to assign players to Teams based on their Player.PartyId using the SocialService:GetPlayersByPartyId() method. When a player joins the experience, the script checks whether they're part of a party. If so, it attempts to assign them to the same team as other party members. If no match is found or the player isn't in a party, they're placed on the team with fewer members to maintain balance.

Team Rebalance with Party Integration

local Teams = game:GetService("Teams")
local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local redTeam = Instance.new("Team")
redTeam.Name = "Red Team"
redTeam.TeamColor = BrickColor.Red()
redTeam.AutoAssignable = false
redTeam.Parent = Teams
local blueTeam = Instance.new("Team")
blueTeam.Name = "Blue Team"
blueTeam.TeamColor = BrickColor.Blue()
blueTeam.AutoAssignable = false
blueTeam.Parent = Teams
local function assignPlayerToTeam(player)
local partyId = player.PartyId
if partyId == "" then
assignBalancedTeam(player)
return
end
local teams = { redTeam, blueTeam }
local matchingTeam = nil
local partyPlayers = SocialService:GetPlayersByPartyId(partyId)
for _, partyPlayer in partyPlayers do
if partyPlayer ~= player and table.find(teams, partyPlayer.Team) then
matchingTeam = partyPlayer.Team
break
end
end
if matchingTeam then
player.Team = matchingTeam
player.TeamColor = matchingTeam.TeamColor
else
assignBalancedTeam(player)
end
end
function assignBalancedTeam(player)
local redCount = #redTeam:GetPlayers()
local blueCount = #blueTeam:GetPlayers()
local chosenTeam = redCount <= blueCount and redTeam or blueTeam
player.Team = chosenTeam
player.TeamColor = chosenTeam.TeamColor
end
local function groupPlayersByParty()
local seenPartyIds = {}
local groupedPlayers = {}
for _, player in Players:GetPlayers() do
if player.PartyId == "" then
table.insert(groupedPlayers, { player })
elseif not table.find(seenPartyIds, player.PartyId) then
table.insert(seenPartyIds, player.PartyId)
local partyPlayers = SocialService:GetPlayersByPartyId(player.PartyId)
table.insert(groupedPlayers, partyPlayers)
end
end
return groupedPlayers
end
-- Call this function to rebalance teams
local function rebalanceTeams()
local groups = groupPlayersByParty()
table.sort(groups, function(a, b)
return #a > #b
end)
for _, player in Players:GetPlayers() do
player.Team = nil
end
for _, group in groups do
local redCount = #redTeam:GetPlayers()
local blueCount = #blueTeam:GetPlayers()
local bestTeam
if redCount <= blueCount then
bestTeam = redTeam
else
bestTeam = blueTeam
end
for _, player in group do
player.Team = bestTeam
player.TeamColor = bestTeam.TeamColor
end
end
for _, player in Players:GetPlayers() do
player:LoadCharacter()
end
end
Players.PlayerAdded:Connect(function(player)
assignPlayerToTeam(player)
player:LoadCharacter()
player:GetPropertyChangedSignal("PartyId"):Connect(function()
if player.PartyId ~= "" then
assignPlayerToTeam(player)
end
end)
end)

HideSelfView

()

호출하는 플레이어의 자기 보기를 숨깁니다. 자기 보기가 이미 숨겨져 있는 동안 이 메서드가 호출되면 아무 것도 수행하지 않습니다.


반환

()

PromptGameInvite

()

PromptGameInvite() 로컬 플레이어를 통해 현재 경험에 친구를 초대할 수 있는 초대 프롬프트를 표시합니다.이 메서드를 호출하기 전에, CanSendGameInviteAsync() 를 사용하여 플레이어가 초대를 보낼 수 있는지 여부를 결정해야 합니다, 이 능력은 플랫폼이나 플레이어에 따라 다를 수 있기 때문입니다.

플레이어 초대 프롬프트에 대한 자세한 내용은 초대 프롬프트 구현, 프롬프트와 알림 사용자 정의 및 런치 데이터 사용을 참조하십시오.

매개 변수

player: Instance

초대 팝업으로 프롬프트하는 Player .

기본값: ""
experienceInviteOptions: Instance

프롬프트를 사용자 지정하기 위한 선택적 ExperienceInviteOptions 개체.

기본값: "nil"

반환

()

코드 샘플

The following code sample uses CanSendGameInviteAsync() to confirm whether the local Player can send an invite. If true, it then prompts the invite using PromptGameInvite().

Sending an Invite

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Function to check whether the player can send an invite
local function canSendGameInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendGameInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canInvite = canSendGameInvite(player)
if canInvite then
SocialService:PromptGameInvite(player)
end

PromptPhoneBook

()

주어진 Player에 전화 책을 요청합니다.플레이어가 누군가를 호출하기로 선택하면 CallInviteStateChanged 이벤트가 발생합니다.전화 번호부를 볼 수 있는 능력은 플레이어에 따라 다를 수 있으므로 PromptPhoneBook() 를 호출하기 전에 CanSendCallInviteAsync() 을 사용해야 합니다.

플레이어가 전화 책을 열 수 없는 경우 오류 대화 상자가 표시됩니다.

이 메서드의 샘플 구현은 Roblox Connect에 참조하십시오.

매개 변수

player: Instance

전화 번호부로 프롬프트할 플레이어.

기본값: ""
tag: string

다양한 전화 부ook 항목 또는 유사한 항목을 구분하는 데 도움이 되는 문자열.예를 들어, 호출하는 플레이어의 현재 캐릭터가 속한 경험 영역을 정의하는 문자열을 전달할 수 있습니다.

기본값: ""

반환

()

코드 샘플

The following code sample, placed within a child LocalScript of a GuiButton, uses CanSendCallInviteAsync() to confirm that the player can make a call. If so, it connects PromptPhoneBook() to the button's Activated event.

SocialService:PromptPhoneBook()

local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local player = Players.LocalPlayer
local button = script.Parent
button.Visible = false
-- Function to check whether the player can send a call invite
local function canSendCallingInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendCallInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canCall = canSendCallingInvite(player)
if canCall then
button.Visible = true
button.Activated:Connect(function()
SocialService:PromptPhoneBook(player, "")
end)
end

ShowSelfView

()

호출하는 플레이어의 자기 보기를 표시합니다. 자기 보기가 이미 표시되는 동안 이 메서드가 호출되면 아무 것도 수행하지 않습니다.

매개 변수

selfViewPosition: Enum.SelfViewPosition

자체 뷰를 배치할 위치.

기본값: "LastPosition"

반환

()

CanSendCallInviteAsync

생성

지정된 Player 가 친구에게 전화 초대를 보낼 수 있는 경우 true 를 반환합니다.전화 부ook을 열 수 있는 능력은 플레이어에 따라 다를 수 있으므로 항상 이 메서드의 결과를 사용해야 합니다 PromptPhoneBook() 호출하기 전에.

이 메서드의 샘플 구현은 Roblox Connect에 참조하십시오.

매개 변수

player: Instance

플레이어의 인스턴스 Player 가 전화 초대를 보낼 수 있습니다.

기본값: ""

반환

지정된 플레이어가 전화 초대를 보낼 수 있는지 여부.

코드 샘플

The following code sample, placed within a child LocalScript of a GuiButton, uses CanSendCallInviteAsync() to confirm that the player can make a call. If so, it connects PromptPhoneBook() to the button's Activated event.

SocialService:PromptPhoneBook()

local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local player = Players.LocalPlayer
local button = script.Parent
button.Visible = false
-- Function to check whether the player can send a call invite
local function canSendCallingInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendCallInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canCall = canSendCallingInvite(player)
if canCall then
button.Visible = true
button.Activated:Connect(function()
SocialService:PromptPhoneBook(player, "")
end)
end

CanSendGameInviteAsync

생성

CanSendGameInviteAsync() 는 지정된 Player 가 현재 경험에 다른 플레이어를 초대할 수 있는 경우 true 를 반환합니다.플레이어를 초대할 수 있는 능력은 플랫폼이나 플레이어에 따라 다를 수 있으므로 항상 이 메서드의 결과를 사용해야 합니다. PromptGameInvite() 를 호출하기 전에.

플레이어 초대 프롬프트에 대한 자세한 내용은 플레이어 초대 프롬프트 구현, 프롬프트와 알림 사용자 정의, 런칭 데이터 사용을 참조하십시오.

매개 변수

player: Instance

플레이어의 인스턴스 Player 가 초대를 보낼 수 있습니다.

기본값: ""
recipientId: number

잠재적 Player.UserId의 선택적 옵션 , 발신자가 특정 받는 사람을 초대할 수 있는지 확인하는 데 사용됩니다.

기본값: 0

반환

지정된 플레이어가 초대를 보낼 수 있는지 여부.

코드 샘플

The following code sample uses CanSendGameInviteAsync() to confirm whether the local Player can send an invite. If true, it then prompts the invite using PromptGameInvite().

Sending an Invite

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Function to check whether the player can send an invite
local function canSendGameInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendGameInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canInvite = canSendGameInvite(player)
if canInvite then
SocialService:PromptGameInvite(player)
end

GetEventRsvpStatusAsync

생성

지정된 이벤트에 대해 로컬 플레이어의 RSVP 상태를 반환합니다.이벤트는 현재 경험에 있어야 하며 이미 시작되지 않아야 합니다.이벤트가 이미 시작되었으면 이 메서드는 오류를 반환합니다.

플레이어에게 이벤트에 대한 RSVP 상태를 변경하도록 요청하려면 PromptRsvpToEventAsync()를 사용할 수 있습니다.

매개 변수

eventId: string

플레이어에게 RSVP 상태를 변경하도록 요청하는 이벤트 ID입니다.현재 경험에 존재하는 유효한 이벤트 ID여야 하며 문자열(숫자가 아님)로 표시됩니다.

기본값: ""

반환

이벤트에 대한 플레이어의 현재 RSVP 상태를 나타내는 Enum.RsvpStatus를 반환합니다.플레이어가 이벤트에 RSVP하지 않았다면 이 값은 Enum.RsvpStatus.None로 반환됩니다.

코드 샘플

The following example checks if a player is RSVP'd to an event; if not, it gives them the option to RSVP. If the player is already RSVP'd, it gives them the option to cancel their RSVP.

The following Script assumes that RunContext is set to Enum.RunContext.Client and that two sibling ProximityPrompts are in place: one for following the event and one for unfollowing the event. The prompts are enabled or disabled based on the player's RSVP status.

SocialService:PromptRsvpToEventAsync()

local SocialService = game:GetService("SocialService")
local EVENT_ID = "YOUR_EVENT_ID"
local followPrompt : ProximityPrompt = script.Parent.FollowProximityPrompt
local unFollowPrompt : ProximityPrompt = script.Parent.UnfollowProximityPrompt
local function updatePrompt(rsvpStatus : Enum.RsvpStatus)
if rsvpStatus == Enum.RsvpStatus.Going then
unFollowPrompt.Enabled = true
followPrompt.Enabled = false
else
unFollowPrompt.Enabled = false
followPrompt.Enabled = true
end
end
local success, currentRsvpStatus = pcall(function()
return SocialService:GetEventRsvpStatusAsync(EVENT_ID)
end)
if not success then
-- Could not retrieve RSVP status; don't enable either proximity prompt
warn("Failed to get RSVP status:", currentRsvpStatus)
return
end
print("CurrentRsvpStatus:", currentRsvpStatus)
updatePrompt(currentRsvpStatus)
unFollowPrompt.Triggered:Connect(function(player)
local rsvpStatus = SocialService:PromptRsvpToEventAsync(EVENT_ID)
updatePrompt(rsvpStatus)
end)
followPrompt.Triggered:Connect(function(player)
local rsvpStatus = SocialService:PromptRsvpToEventAsync(EVENT_ID)
updatePrompt(rsvpStatus)
end)

GetPartyAsync

생성

주어진 partyId와 관련된 모든 멤버에 대한 데이터가 포함된 배열의 사전을 반환합니다.반환된 배열은 경험 내의 모든 활성 서버 인스턴스에서 파티의 현재 상태를 반영하고 각 파티 멤버가 파티 초대를 수락한 시간순으로 정렬됩니다.즉, 배열의 첫 번째 요소가 가장 먼저 수락하고 마지막은 가장 최근의 것입니다.

이 메서드는 현재 경험에 있고 다양한 서버에 걸쳐 있는 모든 파티 멤버에 대한 최신 정보를 검색하는 데 유용하며, 텔레포트, 매치메이킹 또는 파티 기반 게임플레이 로직과 같은 조정된 그룹 행동을 가능하게 합니다.

반환된 배열의 각 사전에는 다음 필드가 포함됩니다:


<th>값 유형</th>
<th>설명</th>
</tr>
</thead>
<tbody>
<tr>
<th><code>사용자 ID</code></th>
<td>번호</td>
<td>플레이어의 <code>Class.Player.UserId</code> 속성.</td>
</tr>
<tr>
<th><code>장소 ID</code></th>
<td>번호</td>
<td>파티 멤버가 현재 있는 장소의 <code>Class.DataModel.PlaceId</code>.</td>
</tr>
<tr>
<th><code>작업 ID</code></th>
<td>문자열</td>
<td>사용자가 현재 속해 있는 서버 인스턴스의 <code>Class.DataModel.JobId</code>.</td>
</tr>
<tr>
<th><code>개인 서버 ID</code></th>
<td>문자열</td>
<td>적용 가능한 경우, 파티 멤버가 개인 또는 예약된 서버에 있을 때의 <code>Class.DataModel.PrivateServerId</code>.</td>
</tr>
<tr>
<th><code>예약된 서버 액세스 코드</code></th>
<td>문자열</td>
<td>해당되는 경우 사용자가 현재 거주하는 예약된 서버의 액세스 코드.<code>Class.TeleportService:TeleportAsync()</code>을 사용하여 파티 멤버를 서로 순간이동하는 데 유용합니다.</td>
</tr>
</tbody>

이 서비스는 Roblox Studio에서 플레이테스트 중에 작동하지 않으므로, 경험의 측면을 테스트하려면 경험을 게시하고 Roblox 응용 프로그램에서 플레이해야 합니다.

매개 변수

partyId: string
기본값: ""

반환

현재 경험에 있는 지정된 파티의 멤버를 나타내는 사전 배열.

코드 샘플

The following example checks if a player is in a party when they join. If so, it retrieves the latest party data using SocialService:GetPartyAsync() and outputs the details of each party member.

SocialService:GetPartyAsync()

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local partyId = player.PartyId
if partyId == "" then
warn("Player is not in a party")
return
end
local success, partyData = pcall(function()
return SocialService:GetPartyAsync(partyId)
end)
if success and partyData then
for _, partyMemberData in partyData do
print(
partyMemberData.UserId,
partyMemberData.PlaceId,
partyMemberData.JobId,
partyMemberData.PrivateServerId,
partyMemberData.ReservedServerAccessCode
)
end
else
warn("Failed to retrieve party data")
end
end)

PromptRsvpToEventAsync

생성

PromptRsvpToEventAsync() 지역 플레이어를 통해 RSVP 상태를 지정된 이벤트로 변경할 수 있는 프롬프트를 표시합니다.

이벤트는 현재 경험에 있어야 하고 이미 시작되지 않았어야 합니다. 이벤트가 이미 시작되었다면 이 메서드가 오류를 반환합니다.

이 메서드를 호출하기 전에 GetEventRsvpStatusAsync()를 사용하여 플레이어의 현재 RSVP 상태를 확인할 수 있습니다.

매개 변수

eventId: string

플레이어에게 RSVP 상태를 변경하도록 요청하는 이벤트 ID입니다.현재 경험에 존재하는 유효한 이벤트 ID여야 하며 문자열(숫자가 아님)로 표시됩니다.

기본값: ""

반환

대화 상자가 닫힌 후 플레이어의 새 RSVP 상태를 나타내는 Enum.RsvpStatus를 반환합니다.플레이어가 RSVP 상태를 변경하지 않고 프롬프트를 닫으면 이 반환됩니다 Enum.RsvpStatus.None 또는 이미 상태를 선택한 경우 오래된 Enum.RsvpStatus 합니다.

코드 샘플

The following example checks if a player is RSVP'd to an event; if not, it gives them the option to RSVP. If the player is already RSVP'd, it gives them the option to cancel their RSVP.

The following Script assumes that RunContext is set to Enum.RunContext.Client and that two sibling ProximityPrompts are in place: one for following the event and one for unfollowing the event. The prompts are enabled or disabled based on the player's RSVP status.

SocialService:PromptRsvpToEventAsync()

local SocialService = game:GetService("SocialService")
local EVENT_ID = "YOUR_EVENT_ID"
local followPrompt : ProximityPrompt = script.Parent.FollowProximityPrompt
local unFollowPrompt : ProximityPrompt = script.Parent.UnfollowProximityPrompt
local function updatePrompt(rsvpStatus : Enum.RsvpStatus)
if rsvpStatus == Enum.RsvpStatus.Going then
unFollowPrompt.Enabled = true
followPrompt.Enabled = false
else
unFollowPrompt.Enabled = false
followPrompt.Enabled = true
end
end
local success, currentRsvpStatus = pcall(function()
return SocialService:GetEventRsvpStatusAsync(EVENT_ID)
end)
if not success then
-- Could not retrieve RSVP status; don't enable either proximity prompt
warn("Failed to get RSVP status:", currentRsvpStatus)
return
end
print("CurrentRsvpStatus:", currentRsvpStatus)
updatePrompt(currentRsvpStatus)
unFollowPrompt.Triggered:Connect(function(player)
local rsvpStatus = SocialService:PromptRsvpToEventAsync(EVENT_ID)
updatePrompt(rsvpStatus)
end)
followPrompt.Triggered:Connect(function(player)
local rsvpStatus = SocialService:PromptRsvpToEventAsync(EVENT_ID)
updatePrompt(rsvpStatus)
end)

이벤트

CallInviteStateChanged

이 이벤트는 플레이어의 호출 초대 상태가 변경될 때 발생합니다.

매개 변수

player: Instance

호출 초대 상태 변경이 있었던 플레이어의 인스턴스 Player

inviteState: Enum.InviteState

새로운 호출 초대 상태.


코드 샘플

SocialService.CallInviteStateChanged

local SocialService = game:GetService("SocialService")
local button = script.Parent
local isPhonebookOpen = false
SocialService.CallInviteStateChanged:Connect(function(_, inviteState)
local isCalling = inviteState == Enum.InviteState.Placed
if isCalling or isPhonebookOpen then
button.Visible = false
else
button.Visible = true
end
end)

GameInvitePromptClosed

이 이벤트는 플레이어가 초대 프롬프트를 닫을 때 발생합니다.

매개 변수

player: Instance

프롬프트를 닫은 플레이어의 Player 인스턴스.

recipientIds: Array

더 이상 채워지지 않음; 빈 배열.


PhoneBookPromptClosed

플레이어가 전화 책을 닫을 때 발생합니다.

매개 변수

player: Instance

전화 부록을 닫은 플레이어의 Player 인스턴스.


콜백

OnCallInviteInvoked

전화 부ook에서 호출이 배치될 때 처리할 콜백입니다.tag 매개 변수는 PromptPhoneBook()에 설명된 것처럼 다른 "입력 지점" 또는 유사한 것들을 구분하는 데 사용할 수 있습니다.단일 콜백만 설정할 수 있습니다.

매개 변수

tag: string

다양한 전화 부ook 입력 지점을 구분하는 데 도움이 되는 문자열.

callParticipantIds: Array

호출에 참여하는 모든 플레이어가 포함된 배열. 호출자는 항상 배열에서 첫 번째 플레이어가 됩니다.


반환

값이 PlaceIdReservedServerAccessCode 키인 테이블, 해당 키의 값은 DataModel.PlaceIdTeleportService:ReserveServer()에서 반환된 서버 액세스 코드입니다.

코드 샘플

SocialService.OnCallInviteInvoked

local SocialService = game:GetService("SocialService")
local TeleportService = game:GetService("TeleportService")
SocialService.OnCallInviteInvoked = function()
local placeId = 0123456789 -- This is the place ID of the desired place to drop call participants into
local accessCode = TeleportService:ReserveServer(placeId)
return { ReservedServerAccessCode = accessCode, PlaceId = placeId }
end