Reserved server code teleporting issue, (plus messagingservice data issue)

I’m experiencing a plethora of issues, from data tables not being sent properly from server to server via MessagingService (sends them as nil), to teleporting players to a reserved server through reserved server code not working (prints out unable to cast value to object)

MAIN MENU TELEPORT TO MAP SCRIPT

game.ReplicatedStorage.PirvateServerEvent.OnServerEvent:Connect(function(plr,serverid,mapid)
		local TS = game:GetService("TeleportService")
		
		local placeId = serverid
		
		local none = nil
		
		local reservedAccessCode = TS:ReserveServer(serverid)
		
		local isprivate = true
		
		local datatosend = {
			mapid;
			reservedAccessCode;
			isprivate
		}
		
		local players = game.Players:GetPlayers() 
		for i = 1,#players do
			game.ReplicatedStorage.loading:Clone().Parent = players[i].PlayerGui
		end
		
		wait(math.random(5,7))
		
		TS:TeleportToPrivateServer(placeId, reservedAccessCode, players, none, datatosend)
end)

The code that teleports players from main menu to a map (this works flawlessly)


MAP REPLICATEDFIRST SCRIPT

local TeleportService = game:GetService("TeleportService")

TeleportService.LocalPlayerArrivedFromTeleport:Connect(function(customloading,teleportData)
	
	local event = game.ReplicatedStorage:WaitForChild("ActivateMapLoader")
	
	local mapid = teleportData[1]
	
	local code = teleportData[2]
	
	local isprivate = teleportData[3]
	
	event:FireServer(mapid,code,isprivate)
	
end)

This script is located in ReplicatedFirst. It collects all the data and sends it out to the Server Script. (works flawlessly aswell)


MAP SERVER SCRIPT

local messagingservice = game:GetService("MessagingService")

local servercode

local isprivate

while wait(math.random(4,8)) do

	local waiting = game.ReplicatedStorage:WaitForChild("Loaded")

	repeat wait() until game.ReplicatedStorage.Loaded.Value == true

      --other server scripts deals with the value above

	local players = game.Players:GetPlayers()

	local playernum = #players

	servercode = game.ReplicatedStorage.ServerCode.Value
	isprivate = game.ReplicatedStorage.IsPrivate.Value
	
	servercode = tostring(servercode)  --this is probably unnecessary but thought it would fix it (it didn't)
	playernum = tonumber(playernum)
	
	print(servercode) --checking if it prints out the correct code (it does)
	
	--[[
	local serverData = {
		servercode,
		playernum,  -- for some reason, the main menu script prints all of these out as nil but in game it works fine
		isprivate
	}
	--]]
	
	
	messagingservice:PublishAsync("ServerList",servercode) -- decided to just send out the reserved server code as a temporary fix for testing

end

This is where some of the issues start. The data table that’s being sent out to the main menu turns everything into nil. Even though when you print everything that’s in the data table in game, it sends out information as it should be (server code, number of players and a boolean value). So I basically just sent out the reserved server code as a temporary fix for testing. But it still won’t teleport the player onto the reserved server (unable to cast value to object) Scroll down to the bolded text that says MENU FETCH DATA which explains the issues further into detail.


MENU FETCH DATA SCRIPT

local messagingService = game:GetService("MessagingService")

local success, errormsg, connection = pcall(function()

	messagingService:SubscribeAsync("ServerList",function(serverData)
		
		local reservedCode = serverData.Data -- if this had a table, I would put serverData[1] for the reserved server code, serverData[2] for number of players in the server, and serverData[3] to see if the player joined through a private server or not
		
		game.ReplicatedStorage.UpdateServerClient:FireAllClients(reservedCode)
		
	end)
	
end)

DATA SENT OUT TO CLIENT’S GUI

game.ReplicatedStorage.UpdateServerClient.OnClientEvent:Connect(function(reservedCode)
	local servertemplate = script.ServerTemplate:Clone()
	
	servertemplate.Name = reservedCode
	
	servertemplate.JoinButton.LocalScript.ServerCode.Value = reservedCode
	
	servertemplate.ServerName.Text = reservedCode
	
	servertemplate.Parent = script.Parent.List
end)

Just like the comment says, it doesn’t receive data correctly. If the data is under a table, everything is set to nil. But if it’s only 1 piece of data (no table) it’s no longer nil. That’s problem #1


GUI BUTTON SCRIPT THAT TELEPORTS PLAYER

function serverid()
	local serverid = 6990583825
	local code = script.ServerCode.Value
	game.ReplicatedStorage.JoinUnofficalMapEvent:FireServer(serverid,code)
end

script.Parent.Activated:Connect(serverid)

SERVER SCRIPT THAT’S BEING FIRED FROM GUI BUTTON

game.ReplicatedStorage.JoinUnofficalMapEvent.OnServerEvent:Connect(function(plr,serverid,code)
	
	local teleportService = game:GetService("TeleportService")
	
	game.ReplicatedStorage.loading:Clone().Parent = plr.PlayerGui
	
	teleportService:TeleportToPrivateServer(serverid, code, plr)

        -- every piece of data was correct (serverid, code, plr) but it still prints out unable to cast value to object?
	
end)

Problem #2 is what the comment says. All data that was sent out was correct. Reserved server code is correct, server id and player as well but it still prints out an unable to cast value to object error.

So those are my main issues. Data tables being sent as nil from map to main menu script via messaging service, and teleporting players to a reserved server with the code also not working.

Any suggestions will help out a ton! Thanks for reading.