PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

CanSendGameInviteAsync

This function indicates whether the specified Player can send game invites. It returns true or false depending on the client’s platform and privacy settings. It can error if targetPlayer is not in the datamodel.

How Game Invites Work

  • User joins a game and presses a developer-constructed button. Activating the button will invoke SocialService/PromptGameInvite|PromptGameInvite(localPlayer).

Step 1

  • This function call will fire a DataType/RBXScriptSignal|rbx::signal (called SocialService/PromptInviteRequested). The CoreScript|CoreScripts are bound to this signal through Reflection and once invoked will show the user a version of the following screen:

Step 2

  • When the user successfully sends an invite, a rbx::signal will fire on the client and server (called SocialService.PromptInviteRequested).

Step 3

See also

This is part of the SocialService class containing a set of APIs that allow you to integrate game invitations into your games.

  • SocialService/PromptGameInvite, prompts the specified player with the game invite screen
  • SocialService/GameInvitePromptClosed, fires when a player closes a game invite prompt

Parameters

Name Type Default Description

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

Returns

Return Type Summary

Whether the specified player can send a game invite


Code Samples


Sending a Game Invite

The following code sample demonstrates how to implement several SocialService APIs to allow players to invite other players to your game.

In order to work as expected, the code sample must be placed in a LocalScript descending from a GuiButton. When the Players/LocalPlayer touches or left clicks the GUI button, it executes openGameInvitePrompt() which opens the game invite prompt using SocialService/PromptGameInvite after firing canSendGameInvite() to check if the player can send game invites using SocialService/CanSendGameInviteAsync.

When the player closes the invite prompt, the invitePromptClosed() function connected to the SocialService/GameInvitePromptClosedevent fires.

local SocialService = game:GetService(“SocialService”)
local Players = game:GetService(“Players”)
local player = Players.LocalPlayer

local function canSendGameInvite(targetPlayer)
	local res, canSend = pcall(SocialService:CanSendGameInvite(targetPlayer))
	return res and canSend
end

local function promptGameInvite(targetPlayer)
	local res, canInvite = pcall(PromptGameInvite(targetPlayer))
	return res and canInvite
end

local function openGameInvitePrompt(targetPlayer)
	local canInvite = canSendGameInvite(targetPlayer)
	if canInvite then
		local promptOpened = promptGameInvite(targetPlayer)
		return promptOpened
	end
	return false
end

local function invitePromptClosed(senderPlayer, recipientIds)
	-- Handle custom logic for players invited by sender
end

local function inputBegan(input, gameProcessed)
	local inputType = input.UserInputType
	local touch = Enum.UserInputType.Touch
	local mouse1 = Enum.UserInputType.MouseButton1

	if inputType == touch or inputType == mouse1 then
		openGameInvitePrompt(player)
	end
end

script.Parent.InputBegan:Connect(inputBegan)
SocialService.GameInvitePromptClosed:Connect(invitePromptClosed)