local u=game:GetService("\080\108\097\121\101\114\115")local R={}local X=require(script:WaitForChild("\082\111\116\097\116\101\100\082\101\103\105\111\110\051"))local function S(u,R)for u,X in pairs(u)do if X==R then return true end end return false end function R.createRegion3FromPart(u)return X.new(u.CFrame,u.Size)end function R.returnRegionFromPlayer(u,R)if u and(u.Character and u.Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"))then for u,R in pairs(R)do local X=R:cast(nil,10000)if#X>=1 then return u,R end end end return nil end function R.getPlayersInRegion(R)local X={}local V={}for u,R in pairs(u:GetPlayers())do if R and R.Character then table.insert(V,R.Character)end end local Q=R:castwhite(V,10000)for R,V in pairs(Q)do if V.Name=="\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"then local R=u:GetPlayerFromCharacter(V.Parent)if R and(R.Character and not S(X,R))then table.insert(X,R)end end end return X end return R


local players = game:GetService('Players')

local detectionAPI = {}

local rAPI = require(script:WaitForChild('RotatedRegion3'))


local function isValueInTable(tableToSearch, tableValue)
	for i, v in pairs(tableToSearch) do
		if v == tableValue then
			return true
		end
	end
	return false
end

function detectionAPI.createRegion3FromPart(part)
	return rAPI.new(part.CFrame, part.Size)
end

function detectionAPI.returnRegionFromPlayer(player, regionList)
	if player and player.Character and player.Character:FindFirstChild('HumanoidRootPart') then
		for regionName, region in pairs(regionList) do
			local partsInRegion = region:cast(nil, 10000)
			if #partsInRegion >= 1 then
				return regionName, region
			end
		end
	end
	return nil
end


function detectionAPI.getPlayersInRegion(region)
	local playersInRegion = {}
	
	local playersa = {}
	for _, v in pairs(players:GetPlayers()) do
		if v and v.Character then
			table.insert(playersa, v.Character)
		end
	end
	
	local parts = region:castwhite(playersa, 10000)
	for _, part in pairs(parts) do
		if part.Name == 'HumanoidRootPart' then
			local player = players:GetPlayerFromCharacter(part.Parent)
			if player and player.Character and not isValueInTable(playersInRegion, player) then
				table.insert(playersInRegion, player)
			end
		end
	end
	return playersInRegion
end

return detectionAPI
