local c=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local u=game:GetService("\083\101\114\118\101\114\083\116\111\114\097\103\101")local p=game:GetService("\080\108\097\121\101\114\115")local K=require(c.Dependencies.LuaUtils.TableUtils)local C=require(u.Source.Managers.MonsterManager)local L=require(c.Source.Common.getAllPlayerRootParts)local Y=require(u.Source.Common.getClosestPartsFrom)return function(c)local u=K.append(L(),C.getAllMonsterParts())local X,i=Y(u,c)local O if X then O=p:GetPlayerFromCharacter(X.Parent)end return O,i end

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

local TableUtils = require(ReplicatedStorage.Dependencies.LuaUtils.TableUtils)
local MonsterManager = require(ServerStorage.Source.Managers.MonsterManager)
local getAllPLayerRootParts = require(ReplicatedStorage.Source.Common.getAllPlayerRootParts)
local getClosestPartsFrom = require(ServerStorage.Source.Common.getClosestPartsFrom)

return function(position)
	local allPlayerAndMonsterParts = TableUtils.append(getAllPLayerRootParts(), MonsterManager.getAllMonsterParts())

	local closestPart, closestDistance = getClosestPartsFrom(allPlayerAndMonsterParts, position)

	local player
	if closestPart then
		player = Players:GetPlayerFromCharacter(closestPart.Parent)
	end

	return player, closestDistance
end
