local L local I=nil local n=nil local M=nil local function Z()return Player and Player.Character end local function z(z)if z==I then return end if n then n:Disconnect()n=nil end if M then M:Disconnect()M=nil end I=z L={Z()}if I~=nil then local Z=CollectionService:GetTagged(I)for I,n in ipairs(Z)do table.insert(L,n)end n=(CollectionService:GetInstanceAddedSignal(I)):Connect(function(I)table.insert(L,I)end)M=(CollectionService:GetInstanceRemovedSignal(I)):Connect(function(I)for n=1,#L,1 do if L[n]==I then L[n]=L[#L]table.remove(L)break end end end)end end local function s()if L then return L end L={}table.insert(L,Z())return L end local function e(L,I)return Vector3.new(math.min(L.X,I.X),math.min(L.Y,I.Y),math.min(L.Z,I.Z))end local function a(L,I)return Vector3.new(math.max(L.X,I.X),math.max(L.Y,I.Y),math.max(L.Z,I.Z))end local function m(L)if L==nil or L.PrimaryPart==nil then return end local I=L.PrimaryPart.CFrame:inverse()local n=Vector3.new(math.huge,math.huge,math.huge)local M=Vector3.new(-math.huge,-math.huge,-math.huge)for L,Z in pairs(L:GetDescendants())do if Z:IsA("\066\097\115\101\080\097\114\116")and Z.CanCollide then local L=I*Z.CFrame local z=Vector3.new(Z.Size.X/2,Z.Size.Y/2,Z.Size.Z/2)local s={Vector3.new(z.X,z.Y,z.Z),Vector3.new(z.X,z.Y,-z.Z),Vector3.new(z.X,-z.Y,z.Z);Vector3.new(z.X,-z.Y,-z.Z),Vector3.new(-z.X,z.Y,z.Z);Vector3.new(-z.X,z.Y,-z.Z);Vector3.new(-z.X,-z.Y,z.Z),Vector3.new(-z.X,-z.Y,-z.Z)}for I,Z in ipairs(s)do local z=L*Z n=e(n,z)M=a(M,z)end end end local Z=M-n if Z.X<0 or Z.Y<0 or Z.Z<0 then return nil end return Z end

local CurrentIgnoreList
local CurrentIgnoreTag = nil

local TaggedInstanceAddedConnection = nil
local TaggedInstanceRemovedConnection = nil

local function GetCharacter()
	return Player and Player.Character
end

local function UpdateIgnoreTag(newIgnoreTag)
	if newIgnoreTag == CurrentIgnoreTag then
		return
	end
	if TaggedInstanceAddedConnection then
		TaggedInstanceAddedConnection:Disconnect()
		TaggedInstanceAddedConnection = nil
	end
	if TaggedInstanceRemovedConnection then
		TaggedInstanceRemovedConnection:Disconnect()
		TaggedInstanceRemovedConnection = nil
	end
	CurrentIgnoreTag = newIgnoreTag
	CurrentIgnoreList = {GetCharacter()}
	if CurrentIgnoreTag ~= nil then
		local ignoreParts = CollectionService:GetTagged(CurrentIgnoreTag)
		for _, ignorePart in ipairs(ignoreParts) do
			table.insert(CurrentIgnoreList, ignorePart)
		end
		TaggedInstanceAddedConnection = CollectionService:GetInstanceAddedSignal(
			CurrentIgnoreTag):Connect(function(ignorePart)
			table.insert(CurrentIgnoreList, ignorePart)
		end)
		TaggedInstanceRemovedConnection = CollectionService:GetInstanceRemovedSignal(
			CurrentIgnoreTag):Connect(function(ignorePart)
			for i = 1, #CurrentIgnoreList do
				if CurrentIgnoreList[i] == ignorePart then
					CurrentIgnoreList[i] = CurrentIgnoreList[#CurrentIgnoreList]
					table.remove(CurrentIgnoreList)
					break
				end
			end
		end)
	end
end

local function getIgnoreList()
	if CurrentIgnoreList then
		return CurrentIgnoreList
	end
	CurrentIgnoreList = {}
	table.insert(CurrentIgnoreList, GetCharacter())
	return CurrentIgnoreList
end

local function minV(a, b)
	return Vector3.new(math.min(a.X, b.X), math.min(a.Y, b.Y), math.min(a.Z, b.Z))
end
local function maxV(a, b)
	return Vector3.new(math.max(a.X, b.X), math.max(a.Y, b.Y), math.max(a.Z, b.Z))
end
local function getCollidableExtentsSize(character)
	if character == nil or character.PrimaryPart == nil then return end
	local toLocalCFrame = character.PrimaryPart.CFrame:inverse()
	local min = Vector3.new(math.huge, math.huge, math.huge)
	local max = Vector3.new(-math.huge, -math.huge, -math.huge)
	for _,descendant in pairs(character:GetDescendants()) do
		if descendant:IsA('BasePart') and descendant.CanCollide then
			local localCFrame = toLocalCFrame * descendant.CFrame
			local size = Vector3.new(descendant.Size.X / 2, descendant.Size.Y / 2, descendant.Size.Z / 2)
			local vertices = {
				Vector3.new( size.X,  size.Y,  size.Z),
				Vector3.new( size.X,  size.Y, -size.Z),
				Vector3.new( size.X, -size.Y,  size.Z),
				Vector3.new( size.X, -size.Y, -size.Z),
				Vector3.new(-size.X,  size.Y,  size.Z),
				Vector3.new(-size.X,  size.Y, -size.Z),
				Vector3.new(-size.X, -size.Y,  size.Z),
				Vector3.new(-size.X, -size.Y, -size.Z)
			}
			for _,vertex in ipairs(vertices) do
				local v = localCFrame * vertex
				min = minV(min, v)
				max = maxV(max, v)
			end
		end
	end
	local r = max - min
	if r.X < 0 or r.Y < 0 or r.Z < 0 then return nil end
	return r
end
