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.
There are two ways you can do this.
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
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.
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.