SocialService facilitates social functions that impact relationships made on the Roblox platform. 它的主要用途是显示 邀请提示 和手机书给玩家,允许他们向朋友通过 PromptGameInvite() 和 0> Class.Social
概要
方法
活动
在玩家的邀请状态变更时触发。
玩家关闭邀请提示时触发。
当玩家关闭电话书提示时,触发。
回调
从电话书放置时的回调。
属性
方法
HideSelfView
隐藏调用玩家的自查看。如果此方法在自视图已隐藏时调用,它将无视。
返回
PromptGameInvite
PromptGameInvite() 显示一个邀请提示,通过此邀请提示本地玩家邀请他们的朋友加入当前体验。在调用此方法之前,您应该使用 CanSendGameInviteAsync() 来确定玩家是否可以发送邀请,因为这个能

有关邀请提示的实现,请参阅Player Invite Prompts。
参数
Class.Player 以弹出邀请提示。
可选的 ExperienceInviteOptions 对象用于自定义提示。
返回
代码示例
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().
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 事件触发。您应该在使用 Class.SocialService:CanSendCallInviteAsync()|CanSendCall
如果玩家无法打开手机书,将显示错误对话框。
有关此方法的示例实现,请参阅Roblox Connect。
参数
返回
代码示例
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.
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
显示调用玩家的自查看。如果此方法在自视图已可见时调用,它将无视。
参数
自视图的位置。
返回
CanSendCallInviteAsync
返回 true 如果给定的 Player 可以发送通话邀请给朋好友。您总是应该使用此方法的结果,在调用 PromptPhoneBook() 之前,因为能够打开手机书的能力可能会因玩家而变得不同。
有关此方法的示例实现,请参阅Roblox Connect。
参数
返回
是否允许指定的玩家发送通话邀请。
代码示例
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.
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() 返回 true 如果给定的 Player 可以邀请其他玩家到当前体验。您总是应该使用此方法的结果,前提是平台或玩家可能会变得不同。
有关玩家邀请提示的更多信息,请参阅玩家邀请提示。
参数
可选 Player.UserId 的潜在 接收者 ,用于检查发件人是否可以邀请该特定接收收件人。
返回
是否允许指定的玩家发送邀请。
代码示例
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().
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
活动
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
当玩家关闭邀请提示时,此事件触发。
参数
回调
OnCallInviteInvoked
当从电话书放置一个调用时,调用处理器。 tag 参数可以用来区分不同的“入口点”或类似的“入口点”,如在 PromptPhoneBook() 中描述。 只有一个调用可以设置。
参数
返回
包含 PlaceId 和 ReservedServerAccessCode 钥匙,其值为 DataModel.PlaceId 和返回 2> Class.TeleportService:ReserveServer()2> 的服务器访问代码, respectivamente.
代码示例
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