Is it possible to detect when player invites someone else

I want to reward players when they invite their friends through the invite friend menu in ESC. I want to use SocialService but I don’t know if it will work. Any help?


Just send it as launch data in the ExperienceInviteOptions when sending the invite request.

Roblox has even put inside of the documentation an example of how to send this over:

local HttpService = game:GetService("HttpService")
local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer

local data = {
	senderUserID = player.UserId,
	spawnLocation = {12, 48, 205.5}
local launchData = HttpService:JSONEncode(data)

-- Construct invite options with launch data
local inviteOptions ="ExperienceInviteOptions")
inviteOptions.LaunchData = launchData

-- Function to check whether the player can send an invite
local function canSendGameInvite(sendingPlayer)
	local success, canSend = pcall(function()
		return SocialService:CanSendGameInviteAsync(sendingPlayer)
	return success and canSend

local canInvite = canSendGameInvite(player)
if canInvite then
	local success, errorMessage = pcall(function()
		SocialService:PromptGameInvite(player, inviteOptions)

Documentation I recommend you check:


Thanks for your reply! I am having trouble understanding what your code means. Do you know how to make an “event” sort of thing that fires when a player invites a friend?

Edit: sorry if it’s hard to understand, what I’m trying to do is to know when a player invited his friend. That’s like the only thing I need to know.

That is exactly what the code does. What it will do is pop up a UI with a bunch of players that you can invite and when a user clicks on invite, it invites the user but due to you having the options set it allow you to save data to the invite (in this case it would be the user who invited you in the launch data). The code I sent is basically doing that, you would then just do Player:GetJoinData() to get the join data.

I recommend checking out the documentation that I linked if your confused because it explains it and gives you more places to check out information in the documentation.

Oh ok, so is there a way to simplify the code so instead of like making someone spawn somewhere different with invite, I just want to get notified immediately when someone invites another player, not when the other player actually joins. is there a way to detect when someone invites another player?

Yea of course, the code is there to edit as you like. What I sent was just an example which Roblox made but is not at all required to follow but rather there as an example.

I mean if you want to be super lazy you should just be able to send the user ID of the player who invited the user and then you would just need to sort out the notification system when the player joins.

Ok so I read the code a little, but it only detects when a player joins through another’s invite.
Player A invites Player B

Player B joins using the invite from Player A
Then the game detects it.

But what I want is:
Player A invites Player B
The game instantly detects it

Doesn’t matter if player B joins or not

Is there a way to do this? Or is it only possible to detect after player B joins?

It is not really possible to do via the social service I don’t think. You could create your own custom UI that store the data you want inside of a datastore but the issue is that it would not sent an invite to the player.

Oh ok, so basically it’s not possible to detect when a player invites another player, but it is possible to detect when a player joins through an invite. Thanks for your reply!

Yea I think so. I had a quick read of the documentation on the social service and that is what I got from it. I could see no event that you can have set up to detect if the player invites or not although thinking about it, that would be useful feature (a bit like how the devproducts system work).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.