"Teleport" Not working as expected

I have a lobby, menu, and game from the un copy-locked Ruddevs Battle Royale.

I’m no scripter, but I can change some things in scripts like adding in game ID’s. So, I changed the game ID in the script to my games ID. From the lobby, you’re supposed to ready up and be teleported to the actual game. Here’s the script:

-- services

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

-- constants

local SQUADS		= ReplicatedStorage.Squads
local REMOTES		= ReplicatedStorage.Remotes

local MATCH_SIZE		= 30
local MAX_QUEUE_TIME	= 10
local MAX_SQUAD_SIZE	= 4

local GAME_ID		= 5157000896

-- variables

local matches	= {}

-- functions

local function NewMatch(queue)
	local match	= {
		Squads		= {};
		Ready		= false;
		ID			= HttpService:GenerateGUID(false);
		Start		= tick();
		Queue		= queue and queue or "Squad";
	}
	
	table.insert(matches, match)
	
	print("Created " .. string.upper(match.Queue) .. " match: " .. match.ID)
	
	return match
end

local function GetMatchSize(match)
	local size	= 0
	
	for _, squad in pairs(match.Squads) do
		size	= size + #squad.Players:GetChildren()
	end
	
	return size
end

local function GetSquadPlayers(squad)
	local players	= {}
	
	for _, p in pairs(squad.Players:GetChildren()) do
		local player	= Players:FindFirstChild(p.Name)
		if player then
			table.insert(players, player)
		end
	end
	
	return players
end

local function SquadReady(squad)
	if #squad.Players:GetChildren() == 0 then
		return false
	end
	
	for _, p in pairs(squad.Players:GetChildren()) do
		if not p.Value then
			return false
		end
	end
	
	return true
end

local function GetMatchPlayers(match)
	local players	= {}
	
	for _, squad in pairs(match.Squads) do
		for _, p in pairs(squad.Players:GetChildren()) do
			local player	= Players:FindFirstChild(p.Name)
			if player then
				table.insert(players, player)
			end
		end
	end
	
	return players
end

local function GetMatch(squad)
	for _, match in pairs(matches) do
		for i, s in pairs(match.Squads) do
			if s == squad then
				return match
			end
		end
	end
end

local function AddSquad(squad)
	local match	= GetMatch(squad)
	
	if not match then
		for _, m in pairs(matches) do
			if m.Queue == squad.Queue.Value and GetMatchSize(m) + #squad.Players:GetChildren() <= MATCH_SIZE then
				if match then
					if GetMatchSize(match) < GetMatchSize(m) then
						match	= m
					end
				else
					match	= m
				end
			end
		end
		
		if not match then
			match	= NewMatch(squad.Queue.Value)
		end
		
		table.insert(match.Squads, squad)
	end
end

local function RemoveSquad(squad)
	for _, match in pairs(matches) do
		for i, s in pairs(match.Squads) do
			if s == squad then
				local players	= GetSquadPlayers(squad)
				
				for _, player in pairs(players) do
					REMOTES.MatchInfo:FireClient(player, "Leave")
				end
				
				table.remove(match.Squads, i)
				break
			end
		end
	end
end

-- events

SQUADS.ChildRemoved:connect(function(squad)
	RemoveSquad(squad)
end)

-- main loop

while true do
	wait(0.5)
	
	for _, squad in pairs(SQUADS:GetChildren()) do
		if SquadReady(squad) then
			AddSquad(squad)
		else
			RemoveSquad(squad)
		end
	end
	
	for i = #matches, 1, -1 do
		local match			= matches[i]
		local numPlayers	= GetMatchSize(match)
		local players		= GetMatchPlayers(match)
		
		for _, squad in pairs(match.Squads) do
			if squad.Queue.Value ~= match.Queue then
				RemoveSquad(squad)
			end
		end
		
		for _, player in pairs(players) do
			REMOTES.MatchInfo:FireClient(player, "Players", match.Queue, numPlayers, MATCH_SIZE, MAX_QUEUE_TIME - math.floor(tick() - match.Start))
		end
		
		if numPlayers == 0 then
			print("Match: " .. match.ID .. " is empty, cleaning up...")
			table.remove(matches, i)
		elseif numPlayers >= MATCH_SIZE or tick() - match.Start > MAX_QUEUE_TIME then
			local success, err = pcall(function()
				print("Match: " .. match.ID .. " is full, sending to game...")
				
				-- combine squads with fill enabled
				for _, squad in pairs(match.Squads) do
					if squad and squad.Parent == SQUADS then
						if squad.Fill.Value then
							print(squad)
							if #squad.Players:GetChildren() < MAX_SQUAD_SIZE then
								for _, other in pairs(match.Squads) do
									if other ~= squad then
										if other.Fill.Value then
											local needed	= MAX_SQUAD_SIZE - #squad.Players:GetChildren()
											if #other.Players:GetChildren() <= needed then
												for _, p in pairs(other.Players:GetChildren()) do
													p:Clone().Parent	= squad.Players
												end
												
												other:Destroy()
											end
										end
									end
								end
							end
						end
					end
				end
				
				-- tell players they're joining
				for _, p in pairs(players) do
					REMOTES.MatchInfo:FireClient(p, "Join")
				end
				
				-- generate access code for new server
				local accessCode	= TeleportService:ReserveServer(GAME_ID)
				
				-- teleport squads
				for _, squad in pairs(match.Squads) do
					if squad and squad.Parent == SQUADS then
						for _, p in pairs(squad.Players:GetChildren()) do
							p.Value	= false
						end
						
						local squadPlayers	= GetSquadPlayers(squad)
						local squadName		= squad.Name
						
						for _, player in pairs(squadPlayers) do
							TeleportService:TeleportToPrivateServer(GAME_ID, accessCode, {player}, nil, squadName)
						end
					end
				end
				
				table.remove(matches, i)
			end)
			if not success then
				warn("oopsie woopsie " .. err)
			end
		end
	end
end

From what I’ve seen, I’m assuming it has somethign to do with the code;

TeleportService:TeleportToPrivateServer(GAME_ID, accessCode, {player}, nil, squadName)

Anyone know how to fix this?

Here’s a link to the un copy-locked game version if you need to go in and play around with it until you have a fix. ​[OPEN SOURCE] Ruddev’s Battle Royale - Roblox

Anything helps, thanks.

1 Like

Have you received any errors so far?

Yes.

 Match: 6535DC54-36C8-4CDD-9759-D4AFFB05121B is full, sending to game...  -  Server - MainScript:183
  16:54:01.890  oopsie woopsie HTTP 403 (Forbidden)  -  Server - MainScript:237

Have you turned on HTTP Request?

How do you do this? like I said, I’m not a programmer

You can find it in the Studio’s Game Settings as seen below:
Example23

If this doesnt solve your issue, let us know.

I know this is off topic, but the old Ui looks so much better.

They need to add a Old Ui button. Just so we can go back to it, haha.

2 Likes

also offtopic but :sob: my studio updated 30 minutes ago

After doing this, I appear to be receiving the same output as before.

Can you show the output you got?

It should not have been the same.

  17:00:17.513  Match: 5B51A9D9-8DC4-488A-B277-70F5DC1875C8 is full, sending to game...  -  Server - MainScript:183
  17:00:17.585  oopsie woopsie HTTP 403 (Forbidden)  -  Server - MainScript:237

maybe its not the same output, but it sure looks the same to me

HTTP 403, means that it can’t find it. ( I believe at least)

What is line 237? ( Oh the print)

So what would the fix be here? And what do you mean by it can’t find what?

I am just as confused as you, honestly, I am not too sure.

So I have 2 places, one for the lobby (its all GUI) and one with the actual game. Perhaps one has to be private? Do they both need HTTP Requests enabled?

You can try to turn the HTTP Request on for the other one just to see.

That doesn’t seem to have worked either. I also enabled third-party teleported (or whatever) and that doesn’t seem to work either. I’m going crazy.