SocialService

Show Deprecated
Not Creatable
Service
Not Replicated

SocialService facilitates social functions that impact relationships made on the Roblox platform. You can prompt players to send invitation requests to their friends through SocialService:PromptGameInvite() and leverage signals when such requests are made.

Code Samples

Sending an Invite

1local SocialService = game:GetService("SocialService")
2local Players = game:GetService("Players")
3
4local player = Players.LocalPlayer
5local button = script.Parent
6
7local function canSendGameInvite(targetPlayer)
8 local res, canSend = pcall(function()
9 return SocialService:CanSendGameInviteAsync(targetPlayer)
10 end)
11 return res and canSend
12end
13
14local function openGameInvitePrompt(targetPlayer)
15 local canInvite = canSendGameInvite(targetPlayer)
16 if canInvite then
17 local res = pcall(function()
18 SocialService:PromptGameInvite(targetPlayer)
19 end)
20 return res
21 end
22 return false
23end
24
25local function invitePromptClosed(senderPlayer)
26 button.Visible = false
27end
28
29local function onActivated()
30 openGameInvitePrompt(player)
31end
32
33SocialService.GameInvitePromptClosed:Connect(invitePromptClosed)
34
35-- Hide the button until it is confirmed that player can send invites
36button.Visible = false
37button.Visible = canSendGameInvite(player)
38button.Activated:Connect(onActivated)

Summary

Properties

Events


Fires when a player closes an invite prompt.

PromptInviteRequested(player: Instance, experienceInviteOptions: Instance): RBXScriptSignal  


Methods

InvokeGameInvitePromptClosed(player: Instance, recipientIds: Array): void  


PromptGameInvite(player: Instance, experienceInviteOptions: Instance): void  

Prompts the given Player with the invite screen.

CanSendGameInviteAsync(player: Instance, recipientId: number): boolean  YIELDS

Indicates whether the given Player can invite other players.

Properties

Events

GameInvitePromptClosed

This event fires when a player closes an invite prompt.

Parameters

player: Instance

The Player instance of the user who closed the prompt.

recipientIds: Array

No longer populated; an empty array.


Code Samples

Sending an Invite

1local SocialService = game:GetService("SocialService")
2local Players = game:GetService("Players")
3
4local player = Players.LocalPlayer
5local button = script.Parent
6
7local function canSendGameInvite(targetPlayer)
8 local res, canSend = pcall(function()
9 return SocialService:CanSendGameInviteAsync(targetPlayer)
10 end)
11 return res and canSend
12end
13
14local function openGameInvitePrompt(targetPlayer)
15 local canInvite = canSendGameInvite(targetPlayer)
16 if canInvite then
17 local res = pcall(function()
18 SocialService:PromptGameInvite(targetPlayer)
19 end)
20 return res
21 end
22 return false
23end
24
25local function invitePromptClosed(senderPlayer)
26 button.Visible = false
27end
28
29local function onActivated()
30 openGameInvitePrompt(player)
31end
32
33SocialService.GameInvitePromptClosed:Connect(invitePromptClosed)
34
35-- Hide the button until it is confirmed that player can send invites
36button.Visible = false
37button.Visible = canSendGameInvite(player)
38button.Activated:Connect(onActivated)

PromptInviteRequested

Roblox Script Security

Parameters

player: Instance
experienceInviteOptions: Instance

Methods

InvokeGameInvitePromptClosed

void
Roblox Script Security

Parameters

player: Instance
recipientIds: Array

Returns

void

PromptGameInvite

void

SocialService:PromptGameInvite() displays an invite screen to the given Player. On this screen, the player may invite their friends to the current experience.

Before using this function, you should use the SocialService:CanSendGameInviteAsync() method to determine whether a player can send an invite, as this can vary depending on the platform or player.

Parameters

player: Instance

The Player to prompt with the invite screen.

experienceInviteOptions: Instance
Default Value: "nil"

Returns

void

No return.

Code Samples

Sending an Invite

1local SocialService = game:GetService("SocialService")
2local Players = game:GetService("Players")
3
4local player = Players.LocalPlayer
5local button = script.Parent
6
7local function canSendGameInvite(targetPlayer)
8 local res, canSend = pcall(function()
9 return SocialService:CanSendGameInviteAsync(targetPlayer)
10 end)
11 return res and canSend
12end
13
14local function openGameInvitePrompt(targetPlayer)
15 local canInvite = canSendGameInvite(targetPlayer)
16 if canInvite then
17 local res = pcall(function()
18 SocialService:PromptGameInvite(targetPlayer)
19 end)
20 return res
21 end
22 return false
23end
24
25local function invitePromptClosed(senderPlayer)
26 button.Visible = false
27end
28
29local function onActivated()
30 openGameInvitePrompt(player)
31end
32
33SocialService.GameInvitePromptClosed:Connect(invitePromptClosed)
34
35-- Hide the button until it is confirmed that player can send invites
36button.Visible = false
37button.Visible = canSendGameInvite(player)
38button.Activated:Connect(onActivated)

CanSendGameInviteAsync

Yields

SocialService:CanSendGameInviteAsync() indicates whether the given Player can invite other players to the current game. If they can, it returns true.

You should always use the result of this function before calling SocialService:PromptGameInvite() since the ability to invite players can vary depending on the platform or player.

Parameters

player: Instance

The Player instance of the user used to determine if the client can send a game invite.

recipientId: number
Default Value: "0"

Returns

Whether the specified player can send an invite.

Code Samples

Sending an Invite

1local SocialService = game:GetService("SocialService")
2local Players = game:GetService("Players")
3
4local player = Players.LocalPlayer
5local button = script.Parent
6
7local function canSendGameInvite(targetPlayer)
8 local res, canSend = pcall(function()
9 return SocialService:CanSendGameInviteAsync(targetPlayer)
10 end)
11 return res and canSend
12end
13
14local function openGameInvitePrompt(targetPlayer)
15 local canInvite = canSendGameInvite(targetPlayer)
16 if canInvite then
17 local res = pcall(function()
18 SocialService:PromptGameInvite(targetPlayer)
19 end)
20 return res
21 end
22 return false
23end
24
25local function invitePromptClosed(senderPlayer)
26 button.Visible = false
27end
28
29local function onActivated()
30 openGameInvitePrompt(player)
31end
32
33SocialService.GameInvitePromptClosed:Connect(invitePromptClosed)
34
35-- Hide the button until it is confirmed that player can send invites
36button.Visible = false
37button.Visible = canSendGameInvite(player)
38button.Activated:Connect(onActivated)