Detecting if player joined through an invite

Hi, so I have a game and I’d like to reward players who invite their friends, and tp them to the player who invited them. I saw some videos which used SocialService to invite players, and it stores the player’s user id in the launch data. However, when some player joins through the invite, launchdata seems to be empty. This is my script.

LocalScript

socialService = game:GetService("SocialService")
players = game:GetService("Players")
localPlayer = players.LocalPlayer

if socialService:CanSendGameInviteAsync(localPlayer) then
	local experienceInviteOptions = Instance.new("ExperienceInviteOptions")
	experienceInviteOptions.PromptMessage = "Support the game!"
	experienceInviteOptions.LaunchData = localPlayer.UserId
	print(experienceInviteOptions.LaunchData)
	experienceInviteOptions.InviteMessageId = notificationId -- There's the actual notification id in the real script
	
	script.Parent.MouseButton1Click:Connect(function()
		socialService:PromptGameInvite(localPlayer, experienceInviteOptions)
	end)
end

Script

game.Players.PlayerAdded:Connect(function(plr)
	local joinData = plr:GetJoinData()
	print(joinData)
	for i,v in pairs(joinData) do
		print(i)
		print(v)
	end
	
	local launchData = joinData.LaunchData
	print(launchData)
	local userId = tonumber(launchData["Inviter"])
	print(userId)
	
	if not userId or not plr:IsFriendsWith(userId) then
		print("returning")
		return
	end
	
	local invitingPlr = game.Players:GetPlayerByUserId(userId)
	local invitingChar = invitingPlr.Character or invitingPlr.CharacterAdded:Wait()
	
	print(invitingPlr.Name)
	print(invitingChar.Name)
	
	local char = plr.Character or plr.CharacterAdded:Wait()
	
	print(char.Name)
	
	char:WaitForChild("HumanoidRootPart").CFrame = invitingChar:WaitForChild("HumanoidRootPart").CFrame
	
	print("tped")
end)

The LocalScript prints out launchdata as expected, printing the player user id. However, the script prints first off a table, then launchdata and an empty line. Is there anything I’m doing wrong?

1 Like

Launch data doesnt seem to work for me as well… I believe it’s a problem with Roblox and all we can do is ask them to fix it as soon as possible

2 Likes

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