How would you detect players that are in a certain area

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    something like this

  2. What is the issue? i can’t figure out how to do it

  3. What solutions have you tried so far? i tried touched events but they didn’t work well

3 Likes

You can use Region3 to detect if player is in a certain area then insert their names in a table if you want.

6 Likes

You could use touch events that change a value in the player called “area” or something like that. Then you can use a script that gets the players area then does something. Since you can use area.value.changed.

2 Likes

You can’t do “area.value.changed”. But you can do: area:GetPropertyChangedSignal(“Value”):Connect(function()

1 Like

That could be used if it was a postal code area sort of roleplay thing if you get me.

1 Like

You can use BasePart:GetTouchingParts() for this
Example:

function IsInside(area, character)
	for i, v in pairs(area:GetTouchingParts()) do
		if (v:IsDescendantOf(character)) then
			return true	
		end
	end
	return false
end

Do note that if CanCollide is set to false, a temporary Touched event must be connected for this to work

2 Likes

Wouldn’t :GetTouchingParts() technically catch the parts that are only intersecting and not the ones that are adjacent?

I heavily encourage you to use Region3 because Touched events are pretty unreliable for cases like this. Especially if you’re going to be trying to seek when the player is no longer in the region.

1 Like

Yes, however in this case he’s using checking if characters are in an area not adjacent or anything which wouldn’t make much difference anyway

1 Like

Region3 does not have rotations and in this case that would definitely be a necessity, which is why GetTouchingParts is preferred for things like this

Use region 3
Put a script in ServerScriptService

local region = Region3.new(Vector3.New(0,0,0) , Vector3.New(0,0,0) ) – change zero’s for the region3’s size
game.Workspace.Part.Size = region.Size
local part = Instance.new(“Part”)
part.Size = region.Size
while true do
wait()
local partsInRegion = game.Workspace:FindPartInRegion3(region, part , max amount of parts inside region3)

for i,v in pairs(partsInRegion) do
print(v.Name)
end
end
end

3 Likes