System: You will be given a Luau script (that has been decompiled). You will rename the variables and functions to sound better, make the script more coherent, and add comments to areas of the script. Return the fixed script without adding ``` as we handle that. If no script has been given, do not produce any output. Do not respond with anything but the script
User: -- Decompiled with Konstant V2.1, a fast Luau decompiler made in Luau by plusgiant5 (https://discord.gg/wyButjTMhM)
-- Decompiled on 2024-11-11 15:00:26
-- Luau version 6, Types version 3
-- Time taken: 0.004760 seconds

local GuiMain_upvr = Instance.new("GuiMain")
GuiMain_upvr.Name = "TacticalVisorMain"
local var2_upvw
allycolor = BrickColor.new("Navy blue") -- Setting global
enemycolor = BrickColor.new("Really red") -- Setting global
unkowncolor = BrickColor.new("Mid gray") -- Setting global
objectcolor = BrickColor.new("Lime green") -- Setting global
local Frame_upvr = Instance.new("Frame")
Frame_upvr.Name = "Visor"
Frame_upvr.Position = UDim2.new(0, 0, 0, 0)
Frame_upvr.Size = UDim2.new(0, 0, 0, 0)
Frame_upvr.BackgroundColor = BrickColor.new("Bright orange")
Frame_upvr.BorderColor = Frame_upvr.BackgroundColor
Frame_upvr.Transparency = 1
Frame_upvr.ZIndex = 1
Frame_upvr.SizeConstraint = "RelativeXX"
Frame_upvr.Parent = GuiMain_upvr
local var4_upvw
function onMove(arg1) -- Line 29
	--[[ Upvalues[1]:
		[1]: GuiMain_upvr (readonly)
	]]
	if arg1.Target == nil then
	else
		if getHumanoid(lastParent(arg1.Target)) then
			if GuiMain_upvr:findFirstChild("Character Display Data") then
				GuiMain_upvr["Character Display Data"]:remove()
			end
			displayData(lastParent(arg1.Target))
			return
		end
		if GuiMain_upvr:findFirstChild("Character Display Data") then
			game:getService("Debris"):addItem(GuiMain_upvr["Character Display Data"], 3)
		end
	end
end
function PlayerCharacter(arg1) -- Line 44
	for _, v in pairs(game.Players:getChildren()) do
		if v.Character == arg1 then
			return v
		end
	end
	return nil
end
function displayData(arg1) -- Line 53
	--[[ Upvalues[1]:
		[1]: GuiMain_upvr (readonly)
	]]
	if GuiMain_upvr:findFirstChild("Character Display Data") then
	else
		local clone_3 = script.DataTemplate:clone()
		local getHumanoid_result1 = getHumanoid(arg1)
		clone_3.Name = "Character Display Data"
		if PlayerCharacter(arg1) ~= nil then
			local PlayerCharacter_result1 = PlayerCharacter(arg1)
			clone_3.CharPicture.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..PlayerCharacter_result1.Name..'&'..PlayerCharacter_result1.userId
			clone_3.CharHealth.Text = "Health: "..math.ceil(getHumanoid_result1.Health)..'/'..getHumanoid_result1.MaxHealth
			clone_3.CharName.Text = arg1.Name
			if PlayerCharacter_result1.Neutral then
				clone_3.CharTeam.Text = "Neutral"
			end
			clone_3.CharType.Text = "Player/"..getHumanoid_result1.Name
		else
			clone_3.CharPicture.Image = ""
			clone_3.CharHealth.Text = "Health: "..math.ceil(getHumanoid_result1.Health)..'/'..getHumanoid_result1.MaxHealth
			clone_3.CharName.Text = arg1.Name
			clone_3.CharType.Text = "Type: "..getHumanoid_result1.Name
		end
		clone_3.Parent = GuiMain_upvr
	end
end
function isPartish(arg1) -- Line 76
	for _, v_2 in pairs({"Part", "Seat", "VehicleSeat", "Flagstand", "SpawnPoint"}) do
		if string.lower(v_2) == string.lower(arg1.className) then
			return true
		end
	end
	return false
end
function getHumanoid(arg1) -- Line 86
	for _, v_3 in pairs(arg1:getChildren()) do
		if v_3.className == "Humanoid" then
			return v_3
		end
	end
end
function isInTable(arg1, arg2) -- Line 94
	for _, v_4 in pairs(arg2) do
		if arg1 == v_4 then
			return true
		end
	end
	return false
end
function lastParent(arg1) -- Line 103
	local var29 = arg1
	local Parent = var29.Parent
	while true do
		if Parent == workspace or Parent == game.Lighting or Parent == nil then
			return var29
		end
	end
end
function selectAllPartsOfHuman(arg1, arg2) -- Line 116
	--[[ Upvalues[1]:
		[1]: Frame_upvr (readonly)
	]]
	-- KONSTANTERROR: [0] 1. Error Block 1 start (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [0] 1. Error Block 1 end (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [4] 3. Error Block 2 start (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [4] 3. Error Block 2 end (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [8] 5. Error Block 3 start (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [8] 5. Error Block 3 end (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [12] 7. Error Block 32 start (CF ANALYSIS FAILED)
	local SelectionBox = Instance.new("SelectionBox")
	SelectionBox.Adornee = arg1
	SelectionBox.Transparency = 1
	if arg2 ~= nil then
		if arg2.TeamColor == game.Players.LocalPlayer.TeamColor and arg2.Neutral == false then
			SelectionBox.Color = allycolor
		elseif arg2.TeamColor ~= game.Players.LocalPlayer.TeamColor and arg2.Neutral == false then
			SelectionBox.Color = enemycolor
		elseif arg2.Neutral then
			SelectionBox.Color = unkowncolor
			-- KONSTANTWARNING: GOTO [77] #43
		end
	else
		SelectionBox.Color = unkowncolor
	end
	-- KONSTANTERROR: [12] 7. Error Block 32 end (CF ANALYSIS FAILED)
end
local tbl_upvr_2 = {}
local tbl_upvr = {}
function scanForHumanoids(arg1) -- Line 148
	--[[ Upvalues[3]:
		[1]: tbl_upvr_2 (readonly)
		[2]: tbl_upvr (readonly)
		[3]: Frame_upvr (readonly)
	]]
	-- KONSTANTERROR: [0] 1. Error Block 1 start (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [0] 1. Error Block 1 end (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [23] 14. Error Block 4 start (CF ANALYSIS FAILED)
	table.insert(tbl_upvr_2, arg1.Parent)
	selectAllPartsOfHuman(arg1.Parent, PlayerCharacter(arg1.Parent))
	arg1.Parent.ChildAdded:connect(function() -- Line 154
		--[[ Upvalues[1]:
			[1]: arg1 (readonly)
		]]
		selectAllPartsOfHuman(arg1.Parent)
	end)
	do
		return
	end
	-- KONSTANTERROR: [23] 14. Error Block 4 end (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [51] 32. Error Block 15 start (CF ANALYSIS FAILED)
	if isPartish(arg1) and arg1.Parent ~= game.Players.LocalPlayer.Character and arg1.Parent.Parent ~= game.Players.LocalPlayer.Character and getHumanoid(lastParent(arg1)) == nil then
		table.insert(tbl_upvr, arg1)
		local SelectionBox_upvr = Instance.new("SelectionBox")
		SelectionBox_upvr.Adornee = arg1
		SelectionBox_upvr.Transparency = 1
		SelectionBox_upvr.Color = objectcolor
		SelectionBox_upvr.Name = "ObjSelection"..arg1.Name
		SelectionBox_upvr.Parent = Frame_upvr
		arg1.AncestryChanged:connect(function() -- Line 166
			--[[ Upvalues[2]:
				[1]: arg1 (readonly)
				[2]: SelectionBox_upvr (readonly)
			]]
			if arg1.Parent == nil or lastParent(arg1).Parent ~= workspace then
				SelectionBox_upvr:remove()
			end
		end)
		return
	end
	SelectionBox_upvr = pairs(arg1:getChildren())
	for _, v_5 in pairs(arg1:getChildren()) do
		scanForHumanoids(v_5)
	end
	-- KONSTANTERROR: [51] 32. Error Block 15 end (CF ANALYSIS FAILED)
end
function onKeyDown(arg1, arg2) -- Line 179
	--[[ Upvalues[1]:
		[1]: var4_upvw (read and write)
	]]
	local any_lower_result1 = arg1:lower()
	if any_lower_result1 == '\b' and var4_upvw.Character ~= nil and var4_upvw.Character:findFirstChild("Head") ~= nil then
		local clone_2 = script.Parent:clone()
		clone_2.Active = true
		clone_2.Parent = workspace
		onDeselected(arg2)
		script.Parent:remove()
	end
	if any_lower_result1 == 'e' then
		onDeselected(arg2)
	end
end
local var44_upvw = false
function onSelected(arg1) -- Line 195
	--[[ Upvalues[4]:
		[1]: var4_upvw (read and write)
		[2]: GuiMain_upvr (readonly)
		[3]: var44_upvw (read and write)
		[4]: var2_upvw (read and write)
	]]
	var4_upvw = game.Players.LocalPlayer
	arg1.KeyDown:connect(function(arg1_2) -- Line 197
		--[[ Upvalues[1]:
			[1]: arg1 (readonly)
		]]
		onKeyDown(arg1_2, arg1)
	end)
	arg1.Move:connect(function() -- Line 198
		--[[ Upvalues[1]:
			[1]: arg1 (readonly)
		]]
		onMove(arg1)
	end)
	if var4_upvw.Character ~= nil and GuiMain_upvr.Parent == nil then
		local clone = script.ColorMessage:clone()
		clone.Parent = GuiMain_upvr
		game:getService("Debris"):addItem(clone, 8)
	end
	if var4_upvw:findFirstChild("PlayerGui") == nil then
		Instance.new("PlayerGui").Parent = var4_upvw
	end
	GuiMain_upvr.Parent = var4_upvw.PlayerGui
	if not var44_upvw then
		scanForHumanoids(workspace)
		var44_upvw = true
	end
	var2_upvw = workspace.ChildAdded:connect(function(arg1_3) -- Line 212
		scanForHumanoids(arg1_3)
	end)
end
script.Parent.Equipped:connect(onSelected)
function onDeselected(arg1) -- Line 216
	--[[ Upvalues[2]:
		[1]: GuiMain_upvr (readonly)
		[2]: var2_upvw (read and write)
	]]
	GuiMain_upvr.Parent = nil
	if var2_upvw ~= nil then
		var2_upvw:disconnect()
		var2_upvw = nil
	end
end
script.Parent.Unequipped:connect(onDeselected)
Assistant: