Region3 stops detecting parts

I have a pretty simple player teleportation system - after countdown ends, players that are inside the Region3 will be teleported.
However I encountered a very strange problem - after teleportation, Region3 stops detecting those players.
Another strange thing is that this happens only when I playtest the game through Roblox, not Studio.

Code (not full):

local SS = game:GetService("ServerStorage")

...

local bindfuncs = SS:WaitForChild("BindFuncs")
local getPlayersAmount = bindfuncs:WaitForChild("GetPlayersAmount")

...

local lobbyTpZone:BasePart = lobbyFolder:FindFirstChild("TpPart", true) --part that represents the Region3

local tpRegion = Region3.new(
	Vector3.new(lobbyTpZone.Position.X-(lobbyTpZone.Size.X/2), lobbyTpZone.Position.Y-(lobbyTpZone.Size.Y/2), lobbyTpZone.Position.Z-(lobbyTpZone.Size.Z/2)),
	Vector3.new(lobbyTpZone.Position.X+(lobbyTpZone.Size.X/2), lobbyTpZone.Position.Y+(lobbyTpZone.Size.Y/2), lobbyTpZone.Position.Z+(lobbyTpZone.Size.Z/2))
)

...

getPlayersInZone.OnInvoke = function()
	local partsInRegion = workspace:FindPartsInRegion3(tpRegion, lobbyFolder, 10000) --lobbyFolder is an instance of lobby, so the lobby itself won't be detected
	return #partsInRegion
end

For the first time, when I :Invoke() function, everything works just fine.
However, after the round, when I :Invoke() bindable function again, it returns 0.

I tried re-creating Region3 again, but it didn’t work.

I don’t have much time left to finish my project - so please help.

1 Like

Not sure, but :FindPartsInRegion3 is deprecated. I’d try using :GetPartBoundsInBox() instead. Instead of having to make a Region3, just use it on the part directly.

https://create.roblox.com/docs/reference/engine/classes/WorldRoot#GetPartBoundsInBox

1 Like

Quick question: how does FilterDescendantsInstances work?
(In OverlapParams)

It is a table of instances, which you can then choose to use it as a Blacklist or Whitelist.

For example:
FilterDescendantsInstances = {character}

All instances within the character model will be taken into account.

I tried doing something like that using Blacklist, but it still considers parts that are descendants.

workspace:GetPartBoundsInBox(lobbyTpZone.CFrame, lobbyTpZone.Size,
	OverlapParams.new({
		FilterDescendantsInstances = {lobbyTpZone},
		FilterType = Enum.RaycastFilterType.Blacklist
}))

edit: bruh i just typed wrong instance

Why does it still consider descendants of an Instance, even though I set FilterType to Blacklist?

Try

FilterDescendantsInstances = lobbyTpZone:GetDescendants()

Edit: Nevermind, I’m rereading it on the wiki now.

Kind of found solution for that now. Although I think it is pretty bad.

getPlayersInZone.OnInvoke = function()
	local partsInRegion = workspace:GetPartBoundsInBox(lobbyTpZone.CFrame, lobbyTpZone.Size)
	local returning = {}
	for i, v in ipairs(partsInRegion) do
		local found = false
		for o, b in ipairs(lobbyFolder:GetDescendants()) do
			if v == b then
				found = true
				break
			end
		end
		if not found then
			table.insert(returning, v)
		end
	end
	return table.getn(returning)
end

Figured it out. Not sure why you have to do it like this. Also realized there’s GetPartsInPart, which is better in your case.

local Params = OverlapParams.new()
Params.FilterDescendantsInstances = {lobbyTpZone}
Params.FilterType = Enum.RaycastFilterType.Whitelist
local partsInRegion = game.Workspace:GetPartsInPart(lobbyTpZone)

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