Hi! How can i create a new server and teleport the player to

Hi, i was trying to add more zones using places to my game and i had an idea,
i want two places, one will be the starter and when the players join it will be teleported to the second place, i want to have a 3x3 maps(grid) in the second place but, there is the thing, when i teleport the player to server with other zone, it is being teleported to any server and not to a server with the zone or a new server

Start place code:

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

local PlaceId = 14239605429

local ZonesData = DataStoreService:GetDataStore("Zones3")
local PlayerZonesData = DataStoreService:GetDataStore("PlayerZones3")

local ServerId = tostring(game.JobId)

Players.PlayerAdded:Connect(function(plr)
	
	local data2 = PlayerZonesData:GetAsync(plr.UserId)
	
	if (not data2) then
		local success, err = pcall(function()
			PlayerZonesData:SetAsync(plr.UserId, 5)
		end)
		
		if not success then
			plr:Kick(err)
			return
		end
		data2 = 5
	end
	
	local Data = ZonesData:GetAsync(data2)
	
	local teleportOptions = Instance.new("TeleportOptions")
	local teleportData = {}
	
	local tp = 1
	
	if not Data then
		teleportData = {placeId = PlaceId}
	else
		if Data[1] then
			teleportData = {
				placeId = PlaceId,
				jobId = Data[1]
			}
			local tp = 2
		else
			teleportData = {placeId = PlaceId}
		end
	end

	teleportOptions:SetTeleportData(teleportData)
	if tp == 1 then
		TeleportService:TeleportPartyAsync(PlaceId, {plr}, teleportOptions)
	else
		TeleportService:TeleportAsync(PlaceId, {plr}, teleportOptions)
	end

	print(data2)
end)

code in the second place:

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

ActualZone = 1

local ZonesData = DataStoreService:GetDataStore("Zones3")
local PlayerZonesData = DataStoreService:GetDataStore("PlayerZones3")

local ServerId = tostring(game.JobId)

Players.PlayerAdded:Connect(function(plr)
	ActualZone = PlayerZonesData:GetAsync(plr.UserId)
	
	
	ZonesData:UpdateAsync(ActualZone, function(value)
		if value then
			value = HttpService:JSONDecode(value)
			
			table.insert(value, {game.JobId, 1})
			
			return HttpService:JSONEncode(value)
		else
			return HttpService:JSONEncode({ServerId})
		end
	end)
	
	
	wait(5)
	
	print(ActualZone)
end)



game:BindToClose(function()

	ZonesData:UpdateAsync(ActualZone, function(value)
		value = HttpService:JSONDecode(value)
		
		print(value)
		
		for a,e in pairs(value) do
			if e[1] == ServerId then
				table.remove(value, a)
				break
			end
		end
		
		print(value)
		
		return HttpService:JSONEncode(value)
	end)
end)

(Srry if my english is bad)

2 Likes

How about trying to reserve a server using the TeleportService:ReserveServer(placeId) function, then setting TeleportOptions.ReserveServerAccessCode to it (You should have the first one as a variable)

I believe both TeleportAsync() and TeleportPartyAsync() acceps the TeleportOptions as a parameter, so just put it in there, and you’re good to go.

1 Like

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