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

GameInvitePromptClosed

This event is a signal invoked when a player has closed the game invite prompt and batches all users and conversation participants into a single array. This prompt can be prompted by the developer or accessed from the SettingsHub menu.

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/CanSendGameInviteAsync, returns true or false depending on the user

Parameters

Name Type Default Description

The player instance who has closed the prompt

An array of ids that have received a game invite when the prompt was opened


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)