My game has a World System, and I would like to add an “Invite Friends” button at the top, and when a user clicks on the notification, they get shown a UI to confirm joining the world, and will then get sent to it and join.
While the invite friends part seems to work fine on the Inviter’s end, the game does not detect any launch data when the invited player joins the game. The game is programmed to return a table with the UserId of the Sender and UserId of the World Owner.
I’ve read through the Documentation multiple times and made my scripts match the examples, although my code proceeds to not work. I’ve also tried searching the Dev Forum with no success.
Here is my code for the Inviter’s End:
local inviteOptions = Instance.new("ExperienceInviteOptions")
inviteOptions.InviteMessageId = "" -- I don't want to public the invite string just in case
inviteOptions.PromptMessage = "Invite friends to join this world!"
-- 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
script.Parent.Activated:Connect(function()
local data = {
senderUserID = player.UserId,
worldToSendTo = tonumber(game.ReplicatedStorage.OwnerId.Value)
}
local launchData = HttpService:JSONEncode(data)
inviteOptions.LaunchData = launchData
local canInvite = canSendGameInvite(player)
if canInvite then
local success, errorMessage = pcall(function()
SocialService:PromptGameInvite(player, inviteOptions)
end)
if success == false then
warn(errorMessage)
end
end
end)
Here is the Invited Player’s End Code:
function FindPlayerJoinData(player)
local launchData
for i = 1, ATTEMPT_LIMIT do
task.wait(RETRY_DELAY)
local joinData = player:GetJoinData()
if joinData.LaunchData ~= "" then
launchData = joinData.LaunchData
break
end
end
if launchData then
local data = HTTPService:JSONDecode(launchData)
print(data)
if data.worldToSendTo then
game.ReplicatedStorage.RemoteEvents.WorldInvitePrompt:FireClient(player, data)
end
else
warn("No launch data received!")
end
end
The game will always print out “No launch data received!”
If anybody has a solution or a way I can fix this, it’d be much appreciated!