SocialService

Mostrar obsoleto

*Pronto este contenido estará disponible en tu idioma seleccionado.

No creable
Servicio
No replicado

SocialService facilitates social functions that impact relationships made on the Roblox platform. Its primary usage is to show invite prompts and the phone book to players, allowing them to send invitation requests to their friends through PromptGameInvite() and PromptPhoneBook() respectively. You may leverage signals when such requests are made.

Resumen

Métodos

Eventos

Llamadas

Propiedades

Métodos

HideSelfView

void

Hides the calling player's self view. If this method is called while the self view is already hidden, it does nothing.


Devuelve

void

PromptGameInvite

void

PromptGameInvite() displays an invite prompt to the local player through which they may invite their friends to the current experience. Before calling this method, you should use CanSendGameInviteAsync() to determine whether the player can send an invite, as this ability may vary depending on the platform or player.

See Player Invite Prompts for more details on implementing invite prompts, customizing prompts and notifications, and using launch data.

Parámetros

player: Instance

The Player to prompt with the invite popup.

experienceInviteOptions: Instance

Optional ExperienceInviteOptions object for customizing the prompt.

Valor predeterminado: "nil"

Devuelve

void

Muestras de código

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

void

Prompts the given Player with the phone book. If the player chooses to call someone, the CallInviteStateChanged event fires. You should use CanSendCallInviteAsync() prior to calling PromptPhoneBook() since the ability to see the phone book may vary depending on the player.

If a player is not eligible to open the phone book, an error dialog is shown.

See Roblox Connect for a sample implementation of this method.

Parámetros

player: Instance

The player to prompt with the phone book.

tag: string

String to help differentiate between various phone book "entry points" or similar. For example, you can pass a string defining what region of an experience the calling player's character is currently in.


Devuelve

void

Muestras de código

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

void

Shows the calling player's self view. If this method is called while the self view is already visible, it does nothing.

Parámetros

selfViewPosition: Enum.SelfViewPosition

The position to place the self view .

Valor predeterminado: "LastPosition"

Devuelve

void

CanSendCallInviteAsync

Proporciona

Returns true if the given Player can send a call invite to a friend. You should always use the result of this method before calling PromptPhoneBook() since the ability to open the phone book may vary depending on the player.

See Roblox Connect for a sample implementation of this method.

Parámetros

player: Instance

The Player instance of the player potentially sending a call invite.


Devuelve

Whether the specified player can send a call invite.

Muestras de código

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

Proporciona

CanSendGameInviteAsync() returns true if the given Player can invite other players to the current experience. You should always use the result of this method before calling PromptGameInvite() since the ability to invite players may vary depending on the platform or player.

See Player Invite Prompts for more details on implementing player invite prompts, customizing prompts and notifications, and using launch data.

Parámetros

player: Instance

The Player instance of the player potentially sending an invite.

recipientId: number

Optional Player.UserId of the potential recipient, used to check whether the sender can invite that specific recipient.

Valor predeterminado: 0

Devuelve

Whether the specified player can send an invite.

Muestras de código

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

Eventos

CallInviteStateChanged

This event fires when a player's call invite state changes.

Parámetros

player: Instance

The Player instance of the player who had a call invite state change.

inviteState: Enum.InviteState

The new call invite state.


Muestras de código

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

This event fires when a player closes an invite prompt.

Parámetros

player: Instance

The Player instance of the player who closed the prompt.

recipientIds: Array

No longer populated; an empty array.


PhoneBookPromptClosed

Fires when a player closes the phone book prompt.

Parámetros

player: Instance

The Player instance of the player who closed the phone book.


Llamadas

OnCallInviteInvoked

Parámetros

tag: string
callParticipantIds: Array

Devuelve

Muestras de código

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