Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying To Make A Box Teleporter - Any Suggestions?

Asked by 10 years ago

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)

1 answer

Log in to vote
0
Answered by 10 years ago

Though I'm not sure if this is right, you might want to try:

if Part.Parent:findFirstChild("Torso") == nil then return end

instead of

if not Part.Name == "Torso" then return end
Ad

Answer this question