------------------------------



targetparts = {}

function updatecam()
	camupdater = runservice.RenderStepped:connect(function()
		workspace.CurrentCamera.CFrame = CFrame.new(Cam.CFrame.p,TARGET.CFrame.p)
	end)
end

function click()
	if mouse.Hit ~= nil then
		for i,v in pairs(workspace:GetChildren()) do
			if v:IsAncestorOf(mouse.Target) then
				if v.Name == TN[1] or TN[2] or TN[3] or TN[4] or TN[5] or TN[6] or TN[7] or TN[8] or TN[9] or TN[10] then -- Cant think of any other way rn sos
					TARGET = mouse.Target
					db = true
				else
					db = false
				end 
			end
		end
		if db == false then
				db = true
				TARGET = mouse.Hit.p
				local targetpart = Instance.new("Part",workspace)
				targetpart.Transparency = 1
				targetpart.CanCollide = false
				targetpart.Anchored = true
				targetpart.Name = "TARGET"
				targetpart.CFrame = mouse.Hit
				table.insert(targetparts,targetpart)
				TARGET = targetpart
				db = false
		end
		if TARGET ~= nil then
			prnt.Main.Lock.LOCK.ZIndex = 2
			prnt.Main.Lock.LOCK.TextColor3 = Color3.new(0,255,0)
		else
			prnt.Main.Lock.LOCK.ZIndex = 0
			prnt.Main.Lock.LOCK.TextColor3 = Color3.new(0.65,0.65,0.65)
		end
	end
end


function keys(k,gpe)
	if not gpe then
		if k.KeyCode == Enum.KeyCode.E then -- zoom in
				activekey = true
				while activekey == true do
					wait()
					if workspace.CurrentCamera.FieldOfView > 20 then
						workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView - 1
					else
						workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView - 0.5
					end
				end
		elseif k.KeyCode == Enum.KeyCode.Q then -- zoom out 
				activekey = true
				while activekey == true do
					wait()
					if workspace.CurrentCamera.FieldOfView > 20 then
						workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + 1
					else
						workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + 0.5
					end
				end
		elseif k.KeyCode == Enum.KeyCode.G then -- Un/Track target
			if TARGET ~= nil then
				if activekey == true then
					activekey = false
					workspace.CurrentCamera.CameraType = "Custom"
					workspace.CurrentCamera.CameraSubject = Cam
					game.Players.LocalPlayer.CameraMaxZoomDistance = 1
					game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
					camupdater:disconnect()
				else
					activekey = true
					game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
					workspace.CurrentCamera.CameraType = "Scriptable"
					game.Players.LocalPlayer.CameraMaxZoomDistance = 1
					if camupdater then
						camupdater:disconnect()
					end
					updatecam()			
				end
			end
		elseif k.KeyCode == Enum.KeyCode.H then -- UnTarget
			for _,v in ipairs(targetparts) do
				v:destroy()
			end
			TARGET = nil
			prnt.Main.Lock.LOCK.ZIndex = 0
			prnt.Main.Lock.LOCK.TextColor3 = Color3.new(0.65,0.65,0.65)
			camupdater:disconnect()
			activekey = false
			workspace.CurrentCamera.CameraType = "Custom"
			workspace.CurrentCamera.CameraSubject = Cam
			game.Players.LocalPlayer.CameraMaxZoomDistance = 1
			game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
		elseif k.KeyCode == Enum.KeyCode.F then
			if TARGET ~= nil then
				pathtoremote.RemoteFunction:InvokeServer(TARGET)
			end
		elseif k.KeyCode == Enum.KeyCode.R then
				pathtoremote.RemoteEvent2:FireServer()
		elseif k.KeyCode == Enum.KeyCode.T then
				pathtoremote.RemoteEvent:FireServer()
		end
	end
end

function keysoff(k,gpe)
	if not gpe then
		if k.KeyCode == Enum.KeyCode.E then
			if activekey == true then
				activekey = false
			end
		elseif k.KeyCode == Enum.KeyCode.Q then
			if activekey == true then
				activekey = false
			end
		end
	end
end

pathtoremote.RemoteEvent2.OnClientEvent:connect(function()
	TARGET = nil
	prnt.Main.Lock.LOCK.ZIndex = 0
	prnt.Main.Lock.LOCK.TextColor3 = Color3.new(0.65,0.65,0.65)
	camupdater:disconnect()
	activekey = false
	workspace.CurrentCamera.CameraType = "Custom"
	workspace.CurrentCamera.CameraSubject = Cam
	game.Players.LocalPlayer.CameraMaxZoomDistance = 1
	game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
end)

UIS.InputBegan:connect(keys)
UIS.InputEnded:connect(keysoff)
mouse.Button1Up:connect(click)