Detecting Player in Region3 with an Event?

Looking on the wiki it does not appear that there is a direct event that fired when a region3 is touch or entered. So I’m pretty sure the only way to do this is set up a loop that calls the workspace:FindPartsInRegion3 function and get the return values. If you wanted you could hook the function up to an event so that when a part is found, it fires a remote to all the clients.

heres the wiki class if you want to check it out, there aren’t too many properties or functions.
https://developer.roblox.com/api-reference/datatype/Region3

2 Likes

Not sure how efficient this would be but perhaps just a heartbeat or a runservice constantly checking that region?

2 Likes

At that point it’d be more efficient to use math.

2 Likes

@Planet_Dad if you wish to let the server know what the user is touching just do the region3 serverly and then do Region3withwhitelist. and then whitelist everycharacter go through the list that it returns and check for any humanoidrootparts then get the player by Game.Players:GetCharacter(HumanoidRootPart.Parent)

2 Likes

Isn’t that what I said, minus the remote Event part?

1 Like

if the region is big use a touched event if its small use a while loop to check if player is in region

1 Like

these are basically map voting pads the player stands on, it sounds like part.Touched:Connect might be the most sensible because it has an event.

The only reason i was thinking Region3 was because i heard the part touched was unreliable

1 Like

Touched is 100% reliable, depending on which enviroment you use it on. On the client it is far more “reliable”, the server sometimes misses some events due to latency and other reasons. TouchEnded however is extremely unreliable, and I would recommend using math if you need to use TouchEnded.

Some examples of math you could use is Magnitude or some formulas.

1 Like

Touched is pretty reliable, TouchEnded is not.

1 Like

Oh i definitely need TouchEnded because when they step off, they get removed from a table.

1 Like

Updated my post.(https://devforum.roblox.com/t/detecting-player-in-region3-wit-an-event/231751/11)

1 Like

Yes for what you’re doing it doesn’t sound like TouchEnded is a good choice. A simple Region3 while loop as others have mentioned would be fine, I wouldn’t bother with connecting it with heartbeat cause a tiny bit of lag isn’t going to matter over a map voting pad. OverHash’s idea with Magnitude would also work, though if you choose this I would make sure your button is a circle.

2 Likes

If I am doing TouchEnded, then the Region3 isnt really needed.

how unreliable is TouchEnded?

This is really supposed to be something so simple. A player stands on a pad, they get added to a table, they step off, they get removed.

1 Like

TouchEnded tends to fire randomly even when player’s are still touching the part. If I remember right animations tend to mess it up including idle animations. You could always try it out for yourself of course in studio.

1 Like

Region3 would be my last goto, math is better. If you need help lemme know

2 Likes

Here’s a suggestion: Instead of using TouchEnded, use Touched for the floor around the voting pads. In other words:

  • When the player touches a pad, remove them from all voting tables and then add them to the one associated with the pad.
  • When the player touches the floor, just remove them from all voting tables.
3 Likes

This is kinda the direction I’m thinking I might go with. This doesn’t need to be a robust system, just simple and quick is what’s needed here.

1 Like

EDIT: It has come to my attention that people are liking this post. The code below does not work correctly, because it creates a region3 everytime the part is touched, instead of creating the regions once and referencing them.

DO NOT use the code below. Let me be clear, do not use the code. Region3’s are perfectly fine.


This is what I am using for my game. It creates a Region3 when a part in a table is touched, and checks if whatever touched it is still touching using FindPartsInRegion3. If the table of parts in the Region3 is nil, then the loop for checking stops until the next touch. I edited it a little bit without testing, but I think it should work still. The whitelist is where you would keep the part that touches the other part.

local TableOfParts = FolderOfParts:GetChildren()

for _,v in pairs(TableOfParts) do
	
v.Touched:Connect(function(ThingThatTouchedOneOfTheParts)
				local CurrentWater = v
				
				local Min = CurrentWater.Position - (0.5 * CurrentWater.Size)
				local Max = CurrentWater.Position + (0.5 * CurrentWater.Size)
				
				local Region = Region3.new(Min,Max)
				
				local Whitelist = {CertainPart}
				

				while wait(.1) do
						
					local CheckField = workspace:FindPartsInRegion3WithWhiteList(Region, Whitelist)
					
					if CheckField[1] == nil then

					else
						
					end
						
					
					
				end
			end
			
		else
			
			
		
		end
	else
	
	end


   end)

end

Maybe not the most efficient, but it’s reliable.

6 Likes

NodeSupport , you are one of the Smartest People in the Entire Universe. I just Used this Method. Its Great! If I could Award you with A Badge , I would!

Your Post Saved Me and My Game!

I am forever thankful!

I recommend you look into Zone+ module. It is VERY nice and I use it for all sorts of stuff! Safe Zones, hit boxes, tycoon button detectors, you name it!

It has events :slight_smile: