Teleport to diffrent place when trouching part

I am creating a system where players stand on a part then all players inside the part get teleported to a diffrtent every 30 seconds how would I do this?

I would simply use Region3 to check what players are standing on that part, then teleport them

https://developer.roblox.com/en-us/api-reference/datatype/Region3

ya okay thanks I wa shtinking region3 then running a loop to check all players and telaport them one by one each 30 second loop

I recommend using GetPartsInPart instead since Region3 can’t be rotated.

How would I get all players from getspartinpart? never used it

Normally all players have a humanoid. Because of this we can check if the touching part has a Humanoid next to it and if it does then it is a player.

local getAllPlayersInPart = function(part)
	local returnValue = {};
	local result = workspace:GetPartsInPart(part);

	for _, p in pairs(result) do
		if(p.Parent:FindFirstChild("Humanoid")) then
			table.insert(returnValue, p);
		end;
	end;

	return returnValue;
end;

local allPlayers = getAllPlayersInPart(**part here**)

Thanks! Once you get all the players how do you telaport them to a place in the game?

Using TeleportService:

local TeleportService = game:GetService("TeleportService");
TeleportService:Teleport(**place id here**, **player here**);

would I just shove allplayers in the player here ? I dont think that would work

You need to iterate through the result:

local allPlayers = getAllPlayersInPart(**part here**)
for _, player in pairs(allPlayers) do
	TeleportService:Teleport(**place id here**, player);
end;

I got “Invalid player to teleport. (x16)” This might be since its in a table so it appears as a value not an object?

NVM realized why. That is their character not the player

For sure! I get the print of each part of the player character, “Leftlower leg” “leftfoot”

local Players = game:GetService("Players")

local getAllPlayersInPart = function(part)
	local returnValue = {};
	local result = workspace:GetPartsInPart(part);

	for _, p in pairs(result) do
		if(p.Parent:FindFirstChild("Humanoid")) then
			table.insert(returnValue, Players:GetPlayerFromCharacter(p.Parent));
		end;
	end;

	return returnValue;
end;

Can you try that?

for sure! I just did this myself to test as I thought to get the player from character since its parts haha

1 Like

exception while signaling: Cannot Teleport in the Roblox Studio. (x16) gonna try in game

This is because TeleportService is disabled on Studio. Try it on the website.

(There used to be an old glitch where you could literally teleport to another person’s game and get all their assets in studio)

It works it just spams errors though why? Is it since it already teleported but it does it anyways

We are trying to teleport the player with every inch of their body. (The head, the torso, the leg, the arm etc… [since all of them are parts]) a simple fix is to do this:

local Players = game:GetService("Players")

local readyToTeleport = {};

local getAllPlayersInPart = function(part)
	local returnValue = {};
	local result = workspace:GetPartsInPart(part);

	for _, p in pairs(result) do
		if(p.Parent:FindFirstChild("Humanoid")) then
			local player = Players:GetPlayerFromCharacter(p.Parent)
			if(not table.find(readyToTeleport, player.UserId)) then
				table.insert(returnValue, player);
				table.insert(readyToTeleport, player.UserId);
			end;
		end;
	end;

	return returnValue;
end;

game:GetService("Players").PlayerRemoving:Connect(function(player)
	for i, v in pairs(readyToTeleport) do
		if(v == player.UserId) then
			table.remove(readyToTeleport, i);
		end;
	end;
end);

This will ensure that the player that started to teleport won’t teleport again. Eventually once the player leaves it removes them from the table. (It is necessary since if the player were to join the same server again it wouldn’t teleport them)