Server tp command

I want a command that is !metserver and it will tp them to a server with Met training it in. Like how pinewood has !petserver that tps them to the pet server were they can host things. I still want the players to stay in the main game but just move to other server. I can also work with a place inside the game.

I am not sure how to make this.

I have tryed to find this on youtube. And nothing.

Please note: If I reply to you late it is because I have not seen your reply and it is late for me.
I also reall dont have a clue on how to code so try to be as clear as you can.

https://developer.roblox.com/en-us/api-reference/class/TeleportService
and

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

local placeId = 0 --Change to ID of destination.

players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message:lower() == "!metserver" then
			if player.UserId == game.CreatorId then
				teleports:TeleportPartyAsync(placeId, players:GetPlayers())
			end
		end
	end)
end)

Would this go in server script storage?

Oh ok thank you so much for the help.

Would testing it work in studio or only in a plubic server?

Hmmm, its not working.

local players = game:GetService(“Players”)
local teleports = game:GetService(“TeleportService”)

local placeId = 8850015739 --Change to ID of destination.

players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message:lower() == “!metserver” then
if player.UserId == game.CreatorId then
teleports:TeleportPartyAsync(placeId, players:GetPlayers())
end
end
end)
end)

No, only the head dev. Let me check

Those errors aren’t even related to the script, I recommend you test in an empty environment. You can’t teleport in studio but you’ll get a console warning indicating as such.

So I did it in the real game and it did not work

What should I do forummer? Do you need a SS of the console?

Replace game.CreatorId with your own user ID.

if player.UserId == game.CreatorId then

Just replace game.CreatorId with your ID.

Worked when testing (I used an invalid ID on purpose).

Does not seem to be working. If this helps its a place that I made with asset manager in studio.

I’m just the head dev for the game not the owner, so I put the owners id in where you said and it did not work

Needs to be the chatters ID (for the command to work). If you want to make this command available to multiple users then you could implement a whitelist.

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

local placeId = 0 --Change to ID of destination.
local whitelisted = {1, 2, 3} --Add user IDs here.

players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message:lower() == "!metserver" then
			if table.find(whitelisted, player.UserId) then
				teleports:TeleportPartyAsync(placeId, players:GetPlayers())
			end
		end
	end)
end)

But the command is not ment for one person, its ment for everyone.

In that case, remove the conditional check entirely.

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

local placeId = 0 --Change to ID of destination.

players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message:lower() == "!metserver" then
			teleports:TeleportPartyAsync(placeId, players:GetPlayers())
		end
	end)
end)

It teleports all the players and no just the people who ran the command. I have it as a script. Does it need to be a local one?