Help with detecting if a model left a area

Hello. I am working on a SCP game with a few other people.
I am trying to make a script that detects if the SCP (which is a model with a humanoid) is out of it’s containment. I built a part which the SCP spawns in and if it leaves, I have a event that fires and turns on the alarms and says that the SCP breached. I tried to do this but it didn’t work. Any help would be appreciated. Here is my script. It is located inside the SCP containment area.

-- Containment Handler

-- Services & Variables

local scpBreachedEvent = game.ReplicatedStorage.SiteStatus.Alert

-- Code

script.Parent.TouchEnded:Connect(function(part)
	local scp = part:FindFirstChild("SCP-173")
	if scp then
		print("Breached")
		scpBreachedEvent:FireAllClients()
	end
end)

-- Triggers
-- Containment Handler

-- Services & Variables
local rs = game:GetService("ReplicatedStorage")
local siteStatus = rs:WaitForChild("SiteStatus")
local alert = siteStatus:WaitForChild("Alert")
local containment = script.Parent
local debounce = false
-- Code

containment.TouchEnded:Connect(function(part)
	if debounce then
		return
	end
	if part.Parent:FindFirstChild("Humanoid") then --checking if touchended was caused by a moving npc/character
		if part.Parent.Name == ("SCP-173") then --im assuming this the name of the npc
			local scp = part.Parent
			if scp then
				debounce = true
				alert:FireAllClients()
				task.wait(10)
				debounce = false
			end
		end
	end
end)

-- Triggers
1 Like

Alternatively, you could check magnitude in a loop, or using EgoMoose’s (easy to use) RotatedRegion3 module. (because normal Region3s aren’t that great)
(Touched can be weird at times)