Teleporting With JobId

I’ve been trying to teleport a player to the JobId for a few hours… too many hours.
Please help. ( this is a cry for help)
This is probably very easy and Im just overlooking or forgot something.

This is what the code that teleports the player looks like (server-sided):

while game.Players:FindFirstChild(plr.Name) do
	local success, errorMessage = pcall(function()
		-- lets join the jobId
		print("did",placeId,localPlayer,jobId)
		-- lets teleport to the JobId
		game:GetService("TeleportService"):TeleportToPlaceInstance(placeId, jobId, localPlayer)
	end)
	if success then
			print("successed")
		--break
	else
		warn(errorMessage)
	end
	wait(5)
	end

Sorry for all the prints, warns etc. lol

This is what got sent on the client (by this server script)

This is what we received on the server:
Screenshot_740

And this is the script on the client that prompts the whole teleport thing (you input your friends name in the textbox and should get teleported to them):

	if script.Parent.leveleditoroptions.TextBox.Text~="" then
			local nahs=false
			for i, v in pairs(game.Players.LocalPlayer:GetFriendsOnline()) do
				print(v.GameId,v.UserName)
				if script.Parent.leveleditoroptions.TextBox.Text==v.UserName then
					local placeId = 17503907776
					-- lets check if we're in the same place
					if v.PlaceId==placeId then
						-- lets join him to his private server (job id)
						local jobId = v.GameId
						while true do
							--game:GetService("TeleportService"):TeleportToPlaceInstance(placeId,jobId,{game.Players.LocalPlayer})
							-- lets use teleportAsync instead but fulfill the same function
							nahs=true
							game.ReplicatedStorage.tpServer:FireServer(placeId,game.Players.LocalPlayer,jobId)
							--[[local success, errorMessage = pcall(function()
								game:GetService("TeleportService"):TeleportAsync(placeId, {game.Players.LocalPlayer},nil,jobId)
							end)
							if success then
								break
							else
								warn(errorMessage)
							end]]
							wait(6)
						end
					else
						warn("different place id")
					end
				else
					print("nah")
				end
			end
			if nahs==false then
				script.Parent.loading.Visible=false
				script.Parent.leveleditoroptions.played.Visible=true
			end
		else
			script.Parent.Frame.RemoteEvent:FireServer(3,script.Parent.leveleditoroptions.TextBox.Text)
		end

This is the script that gets fired (server) from the RemoteEvent:FireServer(3,script.parent.leveleditoroptions.TextBox.Text):

elseif m==3 then
		--local reservedServer=game:GetService("TeleportService"):ReserveServer(17503907776)
		--while plr do
		--	game:GetService("TeleportService"):TeleportToPrivateServer(17503907776,reservedServer,{plr})
		--	task.wait(math.random(2,7))
		--end
-- h is the text in the textBox, we gave.
		if h~="" then
			-- if it is not empty 
			for i, v in pairs(plr:GetFriendsOnline()) do
				print(v.GameId)
				if h==v.Name then
					local placeId = 17503907776
					-- lets check if we're in the same place
					if v.PlaceId==placeId then
						-- lets join him to his private server (job id)
						local jobId = v.JobId
						game:GetService("TeleportService"):TeleportToPlaceInstance(placeId,jobId,{plr})
						
					else
						warn("different place id")
					end
				end
			end
		else
			local placeId = 17503907776
			local reservedServer = game:GetService("TeleportService"):ReserveServer(placeId)

			while true do
				game:GetService("TeleportService"):TeleportToPrivateServer(placeId,reservedServer,{plr},nil)
				wait(7)
			end
		end

So basically we’re trying to teleport to this server:

game:GetService("TeleportService"):TeleportToPrivateServer(placeId,reservedServer,{plr},nil)

But every method I tried didn’t work please help and thanks for reading!

Some answers to questions that will probly show up:

  • The user that im trying to join is in the game and is my friend.
  • The reason for the 3 in the remotevent is that I have other stuff like Solo mode or Multiplayer mode and 3 is the level editor mode. (I didnt show entire script)
1 Like

Sorry that the code looks weird I wrote it throughout 11pm-3am

1 Like