How do I accurately check if a player is in a certain area?

You said using the I don’t need to use the physics engine, that can be innacurate or ineffective or whatever. What would be a better solution in my case: Using the touch and gettouchedparts events or using the stepped event to loop the position check?

That would be fixed with a simple debounce.

1 Like

Debounce not worked, trust me. Now i would use the Zone+ Module mady by @ForeverHD, its really easy and helpfull.

1 Like

Do you know how I could go about regions based on position?

Hey thanks for your reply, does this also work with unions?

Yeah, it should work with unions (and any other part that can be collidable).

This code here will detect when a player is inside a part, and when the player leaves the part.

The code will be repeated but I suggest you modify what I made using debounce

Edit: I added in debounce for simplicity; it was a lot trickier to code than I thought.

-- local script

local Part = game.Workspace:WaitForChild("Vent1").Detect -- The part you want to detect
local tbl = {}  
local debounce = false
local debounce2 = false

game:GetService("RunService").Heartbeat:Connect(function(loop) -- Heartbeat loop
	task.wait() 

	if #tbl == 0 then -- if there isnt anything in table
		if not debounce2 then
			debounce2 = true
			print("Player Outside Part") -- run code

			debounce = false
		end
	end
	
	if #tbl ~= 0 then -- if there is a part in table
		if not debounce then
			debounce = true
			task.wait()
			print("Player Inside Part") -- run code
			debounce2 = false
		end
		
		table.remove(tbl, 1) -- removes the part from table
	end
	Part.Touched:Connect(function() end) -- creates a touch interest 
	local prt = Part:GetTouchingParts()[1] -- gets the touching parts of the specified part
	table.insert(tbl, prt) -- inserts the part into table
end)
3 Likes