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

How to only make players get teleported into a minigame if touching a part?

Asked by 6 years ago
Edited 6 years ago

So, I'm making a flood escapish game, and I want to make something like the lifts from the game, so once intermission runs out and the map loads, only those players get teleported in.

(i want to do it like flood escape 2)

I assume it would work something like this:

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
-- grabbing a table of players touching the part

Then it would probally send it over to the main script.

function teleportGame()
-- grabbing the table of players from the part
players[i].Character.HumanoidRootPart.CFrame = game.Workspace.gameTeleport.CFrame + Vector3.new(math.random(3,6),math.random(3,6),math.random(3,6))
end

Personally, I don't really know. If anyone knows how to grab a table of players touching a part and teleporting the players in that table, that would be great. Thanks.

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

There are two ways you can do this.

Region3

A Region3 is a section of the world, a representation of location and size of a 3D area from one corner to its opposite corner. To create a Region3 from a part, you can use this formula position - (size/2), position + (size/2).

-- Region3.new arguments are Vector3 min, Vector3 max
local tpPart = game.Workspace.gameTeleport
local partRegion = Region3.new(tpPart.Position - (tpPart.Size/2), tpPart.Position + (tp.Size/2))

The Workspace has a FindPartsInRegion3 method (and a variety of similar ones, such as with ignore lists) which will return an array of the parts inside a region.

local function teleportToGame()
    local partsInRegion = game.Workspace:FindPartsInRegion3(partRegion, nil, math.huge)
    -- Region, Instance to ignore, maximum part count


    for _, part in ipairs(partsInRegion) do
        -- Iterating through the array returned
        local player = game.Players:GetPlayerFromCharacter(part.Parent)

        if player then -- if player
            -- Teleport the player 
        end
    end
end

Part:GetTouchingParts()

This next method will be similar to Region3, but you can do it directly from your part. It returns an array of the parts touching it. Note that parts with collisions disabled, they will not count as a touching part.

local function teleportToGame()
    local touchingParts = game.Workspace.gameTeleport:GetTouchingParts()
    -- Region, Instance to ignore, maximum part count


    for _, part in ipairs(touchingParts) do
        -- Iterating through the array returned
        local player = game.Players:GetPlayerFromCharacter(part.Parent)

        if player then -- if player
            -- Teleport the player 
        end
    end
end

And that seems to be it. I'd suggest using Region3 because you can still capture parts even with collisions disabled, but it shouldn't be a problem to use :GetTouchingParts() if the players are able to touch the part with their head or torso, since the legs and arms have collisions disabled.


Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions, then feel free to leave them down in the comments.
0
The Region3 seems to work. Thanks a lot! if you want you can see what im using this for in. (a crude flood escape parody game) https://www.roblox.com/games/2647365119/poop-escape-crude-parody-of-flood-escape RGamesDev 22 — 6y
Ad
Log in to vote
-3
Answered by 6 years ago

if im not wrong i believe flood escape is made by placing an elevator above a teleporting part, and upon descending the players in the elevator would touch the part and get teleported. Its more of a design thing than a code thing.

0
i'm wondering on how to do it like flood escape 2's lift. thanks. RGamesDev 22 — 6y

Answer this question