LaunchData not working properly

I was messing around with the Player:GetJoinData() and LaunchData to understand how it works, so I wanted to make a simple system of creating a Reserved Server when the LaunchData is equal to “privateRoom”, in theory, according with the documentation “Only available on the first join. If the user teleports to another server, the data isn’t included”, but this seems not to work. When the player is teleported to the reserved server, the launchData still appears causing an “infinite” teleportation problem.
Here’s the code:

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")

local function reserveAndTeleport(plr)
	local serverCode = TeleportService:ReserveServer(game.PlaceId)
	TeleportService:TeleportToPrivateServer(game.PlaceId, serverCode, { plr })
end

local function onPlayerAdded(player)
	local launchData = player:GetJoinData().LaunchData
	print(player:GetJoinData())
	print(launchData)
	if launchData then
		if launchData == "privateRoom" then
			print("Private server detected... Teleporting Soon.")
			task.wait(10)
			reserveAndTeleport(player)
		else
			print("LaunchData not recognizable")
		end
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

Just check if the current server is reserved already

if launchData and game.PrivateServerId == "" and game.PrivateServerOwnerId == 0 then

1 Like

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