local d=script.Parent local y=d.Parent local I=y.PlayerIcon local t=I:Clone()local Z=y.Mode local a=y.Parent waitForChild(a,{"\073\100\101\110\116\105\102\105\101\114";"\076\111\099\097\116\105\111\110"})local X=a.Identifier local O=a.Location waitForChild(Z,{"\083\101\097\114\099\104","\084\097\114\103\101\116"})local T=Z.Search local G=Z.Target local N={[BrickColor.new(226)]=true;[BrickColor.new(24)]=true,[BrickColor.new(106)]=true;[BrickColor.new(119)]=true;[BrickColor.new(1025)]=true,[BrickColor.new(38)]=true,[BrickColor.new(11)]=true,[BrickColor.new(1006)]=true;[BrickColor.new(1016)]=true;[BrickColor.new(21)]=true}local o={"\067\108\111\115\101\115\116";"\070\097\114\116\104\101\115\116"}local function c()for d,y in next,o do if T.Value==y then return d end end end local function E(d)return Vector2.new(d.x,d.z)end local function K()for d,y in next,workspace:GetChildren()do if y:IsA("\077\111\100\101\108")and(findChildren(y,body)and not(y==character))then if not((E(y.Torso.Position)-E(character.Torso.Position)).magnitude>distance)then characters[#characters+1]={y;y.Torso.Position-character.Torso.Position}end end end end local function r(d,y)local I=#d:GetChildren()for y,t in next,y do for y=1,I,1 do if d:FindFirstChild(t)then d[t]:Destroy()end end I=#d:GetChildren()end end local function D(d)local y spawn(function()if not y then for d,y in next,N do N[d]=true end D(d)end end)for I,t in next,N do if t then colors[d]=I y=true N[I]=false return end end end local function H(d)if d=="\067\108\111\115\101\115\116"then return 50 elseif d=="\070\097\114\116\104\101\115\116"then return 0 end end local function u()local d=H(T.Value)local y=false for I,t in next,characters do local Z=t[1]local a=t[2]local X=(E(a)).magnitude if T.Value=="\067\108\111\115\101\115\116"then if X<d then d=X G.Value=Z.Name y=true end elseif T.Value=="\070\097\114\116\104\101\115\116"then if X>d then d=X G.Value=Z.Name y=true end end end if not y then G.Value="\078\111\110\101"end end O.MouseButton1Click:connect(function()local d=c()local y=not(d+1>#o)and d+1 or 1 T.Value=o[y]end)T.Changed:connect(function()O.Text=T.Value.."\058"end);(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:connect(function()r(y,{"\080\108\097\121\101\114"})local d=character:GetModelSize()local Z=character.Head.CFrame.lookVector local a=camera.CoordinateFrame.lookVector local O=math.atan2(Z.Z,Z.X)I.Rotation=math.deg(O)+180 O=math.atan2(a.Z,a.X)y.Rotation=-(math.deg(O)-90)characters={}K()for Z,a in next,characters do local X=t:Clone()local O=a[1]local T=a[2]local G=T.Y<-d.Y and"-"or T.Y>d.Y and"\043"or""local N=O.Head.CFrame.lookVector local o=math.atan2(N.Z,N.X)local c,E=.4+(-T.X/distance)/3,.4+(-T.Z/distance)/3 if not colors[O]then D(O)end X.ZIndex=T.Y<-d.Y and I.ZIndex-1 or T.Y>d.Y and I.ZIndex+1 X.Rotation=math.deg(o)+180 X.TextColor=colors[O]or BrickColor.Random()X.Name="\080\108\097\121\101\114"X.Position=UDim2.new(c,0,E,0)X.Text=G.."\062"X.Parent=y end u()X.Text=G.Value end)
--

local scripts_folder = script.Parent
local frame = scripts_folder.Parent
local icon = frame.PlayerIcon
local template = icon:Clone()
local mode_folder = frame.Mode
local radar = frame.Parent
waitForChild(radar, { "Identifier", "Location" })
local identifierLabel = radar.Identifier
local locationButton = radar.Location
waitForChild(mode_folder, { "Search", "Target" })
local mode = mode_folder.Search
local target = mode_folder.Target
local colorList = {
	[BrickColor.new(226)] = true,
	[BrickColor.new(24)] = true,
	[BrickColor.new(106)] = true,
	[BrickColor.new(119)] = true,
	[BrickColor.new(1025)] = true,
	[BrickColor.new(38)] = true,
	[BrickColor.new(11)] = true,
	[BrickColor.new(1006)] = true,
	[BrickColor.new(1016)] = true,
	[BrickColor.new(21)] = true,
}
local modeList = {
	"Closest",
	"Farthest",
}

local function getCurrentModeNumber()
	for index, choice in next, modeList do
		if mode.Value == choice then
			return index
		end
	end
end

local function toV2(v3)
	return Vector2.new(v3.x, v3.z)
end

local function addCharactersInRange()
	for index, instance in next, workspace:GetChildren() do
		if instance:IsA("Model") and findChildren(instance, body) and not (instance == character) then
			if not ((toV2(instance.Torso.Position) - toV2(character.Torso.Position)).magnitude > distance) then
				characters[#characters + 1] = { instance, instance.Torso.Position - character.Torso.Position }
			end
		end
	end
end

local function clearParentOf(parent, list)
	local iterations = #parent:GetChildren()
	for index, name in next, list do
		for i = 1, iterations do
			if parent:FindFirstChild(name) then
				parent[name]:Destroy()
			end
		end
		iterations = #parent:GetChildren()
	end
end

local function assignColor(instance)
	local chosen
	spawn(function()
		if not chosen then
			for color, enabled in next, colorList do
				colorList[color] = true
			end
			assignColor(instance)
		end
	end)
	for color, enabled in next, colorList do
		if enabled then
			colors[instance] = color
			chosen = true
			colorList[color] = false
			return
		end
	end
end

local function returnRangeFromMode(mode)
	if mode == "Closest" then
		return 50
	elseif mode == "Farthest" then
		return 0
	end
end

local function searchPriority()
	local range = returnRangeFromMode(mode.Value)
	local result = false
	for index, information in next, characters do
		local located = information[1]
		local deltaP = information[2]
		local current = toV2(deltaP).magnitude
		if mode.Value == "Closest" then
			if current < range then
				range = current
				target.Value = located.Name
				result = true
			end
		elseif mode.Value == "Farthest" then
			if current > range then
				range = current
				target.Value = located.Name
				result = true
			end
		end
	end
	if not result then
		target.Value = "None"
	end
end

locationButton.MouseButton1Click:connect(function()
	local current = getCurrentModeNumber()
	local nextNumber = not (current + 1 > #modeList) and current + 1 or 1
	mode.Value = modeList[nextNumber]
end)

mode.Changed:connect(function()
	locationButton.Text = mode.Value .. ":"
end)

game:GetService("RunService").RenderStepped:connect(function()
	clearParentOf(frame, { "Player" })
	local characterSize = character:GetModelSize()
	local lookDirection = character.Head.CFrame.lookVector
	local cameraDirection = camera.CoordinateFrame.lookVector
	local rotation = math.atan2(lookDirection.Z, lookDirection.X)
	icon.Rotation = math.deg(rotation) + 180
	rotation = math.atan2(cameraDirection.Z, cameraDirection.X)
	frame.Rotation = -(math.deg(rotation) - 90)
	characters = {}
	addCharactersInRange()
	for index, information in next, characters do
		local clone = template:Clone()
		local located = information[1]
		local deltaP = information[2]
		local symbol = deltaP.Y < -characterSize.Y and "-" or (deltaP.Y > characterSize.Y and "+" or "")
		local facingDirection = located.Head.CFrame.lookVector
		local rotation = math.atan2(facingDirection.Z, facingDirection.X)
		local xScale, yScale = 0.4 + (-deltaP.X / distance) / 3, 0.4 + (-deltaP.Z / distance) / 3
		-- xScale = (not (xScale > 1) and xScale or 1) and (not (xScale < 0) and xScale or 0);
		-- yScale = (not (yScale > 1) and yScale or 1) and (not (yScale < 0) and yScale or 0);
		if not colors[located] then
			assignColor(located)
		end
		clone.ZIndex = deltaP.Y < -characterSize.Y and (icon.ZIndex - 1)
			or (deltaP.Y > characterSize.Y and (icon.ZIndex + 1))
		clone.Rotation = math.deg(rotation) + 180
		clone.TextColor = colors[located] or BrickColor.Random()
		clone.Name = "Player"
		clone.Position = UDim2.new(xScale, 0, yScale, 0)
		clone.Text = symbol .. ">"
		clone.Parent = frame
	end
	searchPriority()
	identifierLabel.Text = target.Value
end)
