Teleporting players from a region3

I’m trying to teleport players above 11 studs if they are inside a specific region3 but it doesnt seem to work like, at all, i have no clue why? i’m inside the region3 and once my function gets called, nothing happens at all, no errors or anything, the only output i get is “loop isnt running” meaning that its not even trying to check if there is any players inside the region3 or not, why?

local function teleportPlayers(regionPart)
	local pos1 = regionPart.Position - (regionPart.Size / 2)
	local pos2 = regionPart.Position + (regionPart.Size / 2)

	local region = Region3.new(pos1, pos2)

	local partsInRegion = workspace:FindPartsInRegion3(region, nil, math.huge)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			print("Player found in the region! "..part.Parent.Name)
			local character = part.Parent
			local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
			if humanoidRootPart then
				humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position + Vector3.new(0, 11, 0))
			end
		else
			warn("nil")
		end
		warn("neither")
	end
	warn("loop isnt running")
end

It’s pretty urgent as I’m trying to script a basic teleporting-based elevator, so if anyone can help me with this, I would really appreciate it.

can u tell me how this called? bc it is a function
do u know the player in that region?

1 Like

use this instead

1 Like

Oh i see, i didnt know it was deprecated. Do i need to use GetPartsInPart() ?

local function teleportPlayers(regionPart)
	local pos1 = regionPart.Position - (regionPart.Size / 2)
	local pos2 = regionPart.Position + (regionPart.Size / 2)

	local region = Region3.new(pos1, pos2)

	local partsInRegion = workspace:GetPartsInPart(region1Part)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			print("Player found in the region! "..part.Parent.Name)
			local character = part.Parent
			local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
			if humanoidRootPart then
				humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position + Vector3.new(0, 11, 0))
			end
		else
			warn("nil")
		end
		warn("neither")
	end
	warn("loop isnt running")
end

Because this isnt working, loop isnt running either, i tried GetPartBoundsInBox() but it’s not working either

local function teleportPlayers(regionPart)
	local pos1 = regionPart.Position - (regionPart.Size / 2)
	local pos2 = regionPart.Position + (regionPart.Size / 2)

	local region = Region3.new(pos1, pos2)

	local partsInRegion = workspace:GetPartBoundsInBox(region.CFrame, region.Size)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			print("Player found in the region! "..part.Parent.Name)
			local character = part.Parent
			local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
			if humanoidRootPart then
				humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position + Vector3.new(0, 11, 0))
			end
		else
			warn("nil")
		end
		warn("neither")
	end
	warn("loop isnt running")
end

Am I doing something wrong? I’m really new to this, so I’m sorry. I can’t quite tell the difference because their API isn’t well explained.

There’s no whitelist or blacklist. I’m trying to teleport every player that are inside a specific region3 above 11 studs

local over = OverlapParams.new()
over.FilterDescendantsInstances = {game.Workspace}
over.FilterType = Enum.RaycastFilterType.Include

local parts = workspace:GetPartBoundsInBox(CFrame.new(Vector3.new(0,0,0)),Vector3.new(15,15,15),over)

print(#parts)

I am sorry I didnt respond sooner!
This works for me it might be that you do not have overlapparams as your third parameter.
Also you can just look it up roblox has a lot of docs for everything

1 Like

Thank you! I got to use the overlapparams correctly


local reg1 = Region3.new(Vector3.new(5, 0, 5), Vector3.new(12, 20, 20))

local newP = Instance.new("Part")
newP.Parent = workspace
newP.Anchored = true
newP.CanCollide = false
newP.Transparency = 0.5
newP.Size = reg1.Size
newP.Position = Vector3.new(newP.Position.X - 69, newP.Position.Y, newP.Position.Z + 32)
newP.Name = "Hello"

local filter = OverlapParams.new()
filter.FilterType = Enum.RaycastFilterType.Exclude
filter.FilterDescendantsInstances = {Door1Left, Door1Right, workspace.Baseplate, soundDoorPart1}

local function teleportPlayers()
	local collisions = workspace:GetPartsInPart(newP, filter)
	
	for i, v in pairs(collisions) do
		print(v.Name)
		if v.Name == "HumanoidRootPart" then
			local humanoidRootPart = v
			humanoidRootPart.Position = humanoidRootPart.Position + Vector3.new(0, 11, 0)
		end
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.