I'm trying to make a box teleporter, so that when someone clicks a SurfaceGUI button, it teleports everyone in the box to my game, as the game the script is in is a lobby. I used a Region3 box, and tried to isolate all parts called 'Torso', to later use them to find characters, using :GetPlayerFromCharacter(), and use TeleportService. Here's a script I've tried:
T = script.Parent.Teleport
script.Parent.Teleport.MouseButton1Click:connect(function ()
local Point1 = Vector3.new(-117.5, 1.82, 106.5)
local Point2 = Vector3.new(-109.1, 11.4, 96.7)
local Region = Region3.new(Point1, Point2)
for _,Part in pairs(game.Workspace:FindPartsInRegion3(Region, nil, 100)) do
if not Part.Name == "Torso" then return end
local player = game.Players:GetPlayerFromCharacter(Part.Parent)
if player then
game:GetService("TeleportService"):Teleport(142967816, player)
end
end
end)
I've also tried this script:
script.Parent.Teleport.MouseButton1Click:connect(function ()
local Point1 = Vector3.new(-117.5, 1.82, 106.5)
local Point2 = Vector3.new(-109.1, 11.4, 96.7)
local Region = Region3.new(Point1, Point2)
parts = game.Workspace:FindPartsInRegion3(Region, nil, 100)
for i = 1, #parts do
if parts[i].Name ~= "Torso" then return end
local player = game.Players:GetPlayerFromCharacter(parts[i].Parent)
if player then
game:GetService("TeleportService"):Teleport(142967816, player)
end
end
end)
